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:
co-authored by
Claude Opus 5.5
morluto
morluto
parent
c6166d4b56
commit
bcb60c179e
@@ -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(`
|
||||
|
||||
@@ -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) ||
|
||||
|
||||
Reference in New Issue
Block a user