From f1088e67652956be9d629e963f49573c4603d46c Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 14 Nov 2023 17:22:42 +0900 Subject: [PATCH] perf(dynamic import): use string check instead of regex --- src/utils/transform/transform-dynamic-import.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/utils/transform/transform-dynamic-import.ts b/src/utils/transform/transform-dynamic-import.ts index 52ff4c34a..ec2ee4ea9 100644 --- a/src/utils/transform/transform-dynamic-import.ts +++ b/src/utils/transform/transform-dynamic-import.ts @@ -20,14 +20,12 @@ const toEsmFunctionString = ((imported: Record) => { 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; }