Skip to content

Commit

Permalink
fix(analyze): allow import statement after } (resolves #166)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jan 11, 2024
1 parent 45d8a29 commit 0d6b0b2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ export interface DefaultExport extends ESMExport {
}

export const ESM_STATIC_IMPORT_RE =
/(?<=\s|^|;)import\s*([\s"']*(?<imports>[\p{L}\p{M}\w\t\n\r $*,/{}@.]+)from\s*)?["']\s*(?<specifier>(?<="\s*)[^"]*[^\s"](?=\s*")|(?<='\s*)[^']*[^\s'](?=\s*'))\s*["'][\s;]*/gmu;
/(?<=\s|^|;|\})import\s*([\s"']*(?<imports>[\p{L}\p{M}\w\t\n\r $*,/{}@.]+)from\s*)?["']\s*(?<specifier>(?<="\s*)[^"]*[^\s"](?=\s*")|(?<='\s*)[^']*[^\s'](?=\s*'))\s*["'][\s;]*/gmu;
export const DYNAMIC_IMPORT_RE =
/import\s*\((?<expression>(?:[^()]+|\((?:[^()]+|\([^()]*\))*\))*)\)/gm;
const IMPORT_NAMED_TYPE_RE =
/(?<=\s|^|;)import\s*type\s+([\s"']*(?<imports>[\w\t\n\r $*,/{}]+)from\s*)?["']\s*(?<specifier>(?<="\s*)[^"]*[^\s"](?=\s*")|(?<='\s*)[^']*[^\s'](?=\s*'))\s*["'][\s;]*/gm;
/(?<=\s|^|;|})import\s*type\s+([\s"']*(?<imports>[\w\t\n\r $*,/{}]+)from\s*)?["']\s*(?<specifier>(?<="\s*)[^"]*[^\s"](?=\s*")|(?<='\s*)[^']*[^\s'](?=\s*'))\s*["'][\s;]*/gm;

export const EXPORT_DECAL_RE =
/\bexport\s+(?<declaration>(async function\s*\*?|function\s*\*?|let|const enum|const|enum|var|class))\s+\*?(?<name>[\w$]+)/g;
Expand Down
9 changes: 8 additions & 1 deletion test/imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ const staticTests = {
specifier: "bar",
},
],
"function a(){}import baz, { x, y as z } from 'baz'": [
{
defaultImport: "baz",
namedImports: { x: "x", y: "z" },
specifier: "baz",
},
],
};

staticTests[
Expand Down Expand Up @@ -239,7 +246,7 @@ describe("findStaticImports", () => {
it(input.replace(/\n/g, "\\n"), () => {
const matches = findStaticImports(input);
const expected = Array.isArray(_results) ? _results : [_results];
expect(expected.length).toEqual(matches.length);
expect(matches.length).toEqual(expected.length);
for (const [index, test] of expected.entries()) {
const match = matches[index];
expect(match.type).to.equal("static");
Expand Down

0 comments on commit 0d6b0b2

Please sign in to comment.