Skip to content

Commit

Permalink
fix import parser for multiple lines
Browse files Browse the repository at this point in the history
  • Loading branch information
wpdas committed Mar 7, 2024
1 parent fa5fc44 commit b4c5736
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b4c5736

Please sign in to comment.