Skip to content

Commit

Permalink
Support dynamic import
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobozzz committed Dec 24, 2021
1 parent 6712b99 commit 92e7c79
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/steps/generateChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FileNotFoundError } from "~/utils/errors";
import type { Alias, Change, ProgramPaths, TextChange } from "~/types";

export const IMPORT_EXPORT_REGEX =
/(?:require\(|(?:import|export) (?:.*from )?)['"]([^'"]*)['"]\)?/g;
/(?:(?:require\(|import\()|(?:import|export) (?:.*from )?)['"]([^'"]*)['"]\)?/g;

const PATHS = [
".js",
Expand Down
10 changes: 10 additions & 0 deletions test/steps/generateChanges.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ describe("steps/generateChanges", () => {
]
`);
});

it("matches dynamic import statements", () => {
const result = regex.exec(`import('package');`);
expect(result).toMatchInlineSnapshot(`
Array [
"import('package')",
"package",
]
`);
});
});

describe(aliasToRelativePath.name, () => {
Expand Down

0 comments on commit 92e7c79

Please sign in to comment.