Skip to content

Commit

Permalink
perf(dynamic import): use string check instead of regex
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Nov 14, 2023
1 parent 6eac49b commit f1088e6
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/utils/transform/transform-dynamic-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ const toEsmFunctionString = ((imported: Record<string, unknown>) => {

const handleDynamicImport = `.then(${toEsmFunctionString})`;

const esmImportPattern = /\bimport\b/;

export const transformDynamicImport = (
filePath: string,
code: string,
) => {
// Naive check
if (!esmImportPattern.test(code)) {
// Naive check (regex is too slow)
if (!code.includes('import')) {
return;
}

Expand Down

0 comments on commit f1088e6

Please sign in to comment.