From 78dbc31e43cf55ad9c330fa0faeb83fd4b3e41c3 Mon Sep 17 00:00:00 2001 From: Chris Tate Date: Tue, 20 Oct 2026 01:51:57 -0500 Subject: [PATCH] Find dynamic imports with a comment before their parenthesis The on-demand import scan tested each file's text for `import(` before reading its calls, so `import /* note */ ("pkg")` was never followed: the workspace package it loads and that package's npm dependencies were left out of the module graph, and the dependency was refused with SC2013. A file is now skipped only when it does not contain the keyword, and its literal import() calls are read from the syntax. The workspace-dynamic-import case loads its package with such a comment. --- packages/compiler/src/frontend/pipeline.ts | 7 ++++--- tests/fixtures/npm/cases/workspace-dynamic-import/main.ts | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) 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();