From b4c57360c64b66f36765f5edc955d3d8dba9238e Mon Sep 17 00:00:00 2001 From: Wenderson Pires Date: Thu, 7 Mar 2024 19:47:41 -0300 Subject: [PATCH] fix import parser for multiple lines --- lib/parse.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/parse.js b/lib/parse.js index f17a62c..31d3350 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -83,10 +83,26 @@ const removeExports = (c) => c .replaceAll("export const", "const") .replaceAll("export default function", "function") - .replaceAll(/^(export)(?:.*?(default))*.*$/gm, ""); + .replaceAll(/^(export)(?:.*?(default))*.*$/gm, ""); // TODO: Test export default with multiple lines + +const removeImports = (c) => { + // Remove line breaks + const importItems = c.match(/(import)(.*?)(from)/gs); + // Uma vez encontrado os imports, deve alinhar todos em uma linha + if (importItems) { + importItems.forEach((item) => { + // Replace items and put them in line + const itemWithoutLineBreaks = item.replace(/\r?\n|\r/g, ""); + c = c.replace(item, itemWithoutLineBreaks); + }); + } -const removeImports = (c) => - c.replaceAll(/^(import)(?:.*?(as))?(?:.*?(as))?(?:.*?(from))*.*$/gm, ""); + // Remove all import statements + return c.replaceAll( + /^(import)(?:.*?(as))?(?:.*?(as))?(?:.*?(from))*.*$/gm, + "", + ); +}; const removeComments = (c) => c.replace(/\/\*[\s\S]*?\*\/|(?<=[^:])\/\/.*|^\/\/.*/g, "").trim();