diff --git a/src/utils/parseReactSvgContent.ts b/src/utils/parseReactSvgContent.ts index 0d8c677..ee82789 100644 --- a/src/utils/parseReactSvgContent.ts +++ b/src/utils/parseReactSvgContent.ts @@ -1,33 +1,46 @@ -import { parse, print, type Module } from "@swc/core"; +import prettier from "prettier"; interface ParseReactSvgOptions { componentName: string; svgCode: string; typescript: boolean; - minify?: boolean; } export const parseReactSvgContent = async ({ componentName, svgCode, typescript, - minify = false, }: ParseReactSvgOptions) => { - let structuredCode = ""; + const reactifiedSvg = svgCode + .replace(") => (\n ${svgCode.replace(") => (\n ${reactifiedSvg}\n);\n\n` + `export { ${componentName} };`; } else { - structuredCode = `const ${componentName} = (props) => (\n ${svgCode.replace(" (\n ${reactifiedSvg}\n);\n\nexport { ${componentName} };`; } - const ast: Module = await parse(structuredCode, { - syntax: typescript ? "typescript" : "ecmascript", - ...(typescript ? { tsx: true } : { jsx: true }), + const formatted = await prettier.format(structuredCode, { + parser: typescript ? "typescript" : "babel", + semi: true, + singleQuote: false, + trailingComma: "es5", }); - const { code } = await print(ast, { minify }); - return code; + + return formatted; };