Skip to content

Commit 7ea5bc2

Browse files
authored
Merge pull request #1082 from joshunrau/patches
fix: use __import for already dynamic imports
2 parents a915017 + af8dd41 commit 7ea5bc2

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

packages/instrument-bundler/src/transform.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ export function transformImports(code: string) {
2727
moduleSpecifier,
2828
startIndex: _startIndex
2929
} of parseImports(code)) {
30-
if (isDynamicImport) {
31-
continue;
32-
}
3330
const endIndex = _endIndex + indexDiff;
3431
const startIndex = _startIndex + indexDiff;
3532
const source = code.slice(startIndex, endIndex);
36-
const replacement = `const ${transformImportClause(importClause!)} = await __import(${moduleSpecifier.code})`;
33+
34+
let replacement: string;
35+
if (isDynamicImport) {
36+
replacement = source.replace(/^import\(/, '__import(');
37+
} else {
38+
replacement = `const ${transformImportClause(importClause!)} = await __import(${moduleSpecifier.code})`;
39+
}
3740
indexDiff += replacement.length - source.length;
3841
code = code.slice(0, startIndex) + replacement + code.slice(endIndex, code.length);
3942
}

0 commit comments

Comments
 (0)