fix(browser): read expression-free template literals as module specifiers (#2842)

Captured-bundle chunk edges and source-map original module edges only
accepted quoted string literals as import()/require() specifiers. Bundlers
such as rolldown emit plain constants as expression-free template literals
(import(`./chunk.js`)), so statically known dependencies were dropped while
completeness stayed complete. Read both sites through the shared exact-literal
reader (stringValue); template literals with substitutions stay unrecognized.

On OWASP Juice Shop v20.3.0 this recovers 8 lazy chunk edges (previously 0).

Fixes #2841
Fixes #2599

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: morluto <17176810+morluto@users.noreply.github.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
Shubham Ahuja
2026-10-14 06:40:25 +08:00
committed by GitHub
co-authored by Claude Opus 5.5 morluto morluto
parent c6166d4b56
commit bcb60c179e
4 changed files with 82 additions and 18 deletions
+22
View File
@@ -662,6 +662,28 @@ describe("web metadata key semantics", () => {
});
});
it("reads expression-free template dynamic imports as chunk edges", () => {
const result = analyzeCapturedWebBundle(
inspection(`
import(\`./lazy.js\`);
import("./quoted.js");
import(\`./\${name}.js\`);
`),
);
expect(result.observations.chunks.edges).toEqual([
expect.objectContaining({
kind: "dynamic_import",
specifier: "./lazy.js",
resolved_url: `${origin}/assets/lazy.js`,
}),
expect.objectContaining({
kind: "dynamic_import",
specifier: "./quoted.js",
}),
]);
});
it("does not infer call names from dynamic computed identifiers", () => {
const result = analyzeCapturedWebBundle(
inspection(`
+11 -8
View File
@@ -123,14 +123,17 @@ const inspectNode = (
node,
accumulator,
});
else if (t.isImportExpression(node) && t.isStringLiteral(node.source))
addEdge({
script,
specifier: node.source.value,
kind: "dynamic_import",
node,
accumulator,
});
else if (t.isImportExpression(node)) {
const specifier = stringValue(node.source);
if (specifier !== undefined)
addEdge({
script,
specifier,
kind: "dynamic_import",
node,
accumulator,
});
}
if (t.isObjectProperty(node)) inspectRouteProperty(script, node, accumulator);
if (
t.isCallExpression(node) ||