diff --git a/packages/compiler/src/frontend/pipeline.ts b/packages/compiler/src/frontend/pipeline.ts index 725ff48cd..1bb34bc3b 100644 --- a/packages/compiler/src/frontend/pipeline.ts +++ b/packages/compiler/src/frontend/pipeline.ts @@ -127,9 +127,10 @@ function addDynamicImportGraph(load: LoadResult, scanned: Set): void const sf = queue.pop()!; if (sf.fileName.includes("/node_modules/")) continue; const specs: string[] = []; - const calls = /\bimport\s*\(/.test(sf.text) - ? moduleSourceCandidates(load.program, sf).calls - : []; + // Every literal import() in the file, read from the syntax: a comment + // can stand between the keyword and its parenthesis. A file without + // the keyword has none. + const calls = sf.text.includes("import") ? moduleSourceCandidates(load.program, sf).calls : []; for (const call of calls) { const arg = call.arguments.nodes[0]; if ( diff --git a/tests/fixtures/npm/cases/workspace-dynamic-import/main.ts b/tests/fixtures/npm/cases/workspace-dynamic-import/main.ts index 59a7b88a9..2068f3c4b 100644 --- a/tests/fixtures/npm/cases/workspace-dynamic-import/main.ts +++ b/tests/fixtures/npm/cases/workspace-dynamic-import/main.ts @@ -1,10 +1,10 @@ -// A workspace package the program loads on demand through import(): its +// A workspace package the program loads on demand with a dynamic import: its // own npm dependency (installed only in the workspace package's // node_modules) compiles with it, although neither is part of the startup -// module graph. +// module graph. A comment can stand between `import` and its parenthesis. async function main(): Promise { console.log("before"); - const m = await import("wsdynamic"); + const m = await import /* loaded on demand */ ("wsdynamic"); console.log(m.greet("world")); } main();