Skip to content

Commit 339797a

Browse files
robertsLandoclaude
andcommitted
fix(detector): reject non-string specifiers in dynamic import matcher
Guard visitorDynamicImport against `import(0)` / `import(true)` so a numeric or boolean literal can't flow through the walker as an alias and crash downstream string checks (e.g. isBuiltin's moduleName.startsWith). Addresses Copilot review feedback on PR #268. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent e3d455b commit 339797a

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

lib/detector.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,15 @@ function visitorDynamicImport(n: babelTypes.Node) {
204204
return null;
205205
}
206206

207-
return { v1: getLiteralValue(n.arguments[0] as babelTypes.Literal) };
207+
// Module specifiers are always strings — reject `import(0)` / `import(true)`
208+
// so a non-string value can't reach the walker's alias handling.
209+
const value = getLiteralValue(n.arguments[0] as babelTypes.Literal);
210+
211+
if (typeof value !== 'string') {
212+
return null;
213+
}
214+
215+
return { v1: value };
208216
}
209217

210218
/** Matches `path.join(__dirname, "lit")` — treats the joined path as a snapshot asset reference. */

0 commit comments

Comments
 (0)