fix(javascript): read substitution-free templates as exact strings
Static application analysis read call arguments only from quoted string literals. A template literal without substitutions denotes the same exact string, yet `fetch(`https://x`)`, `localStorage.setItem(`k`)`, `new Worker(`./w.js`)`, and `require(`./dep.js`)` produced no endpoint, an unnamed storage node, or an unresolved reference expression instead of the facts their quoted spellings produce. Electron IPC and data-effect readers already accepted these templates. Read substitution-free templates in the shared static string and argument readers so both spellings produce the same graph. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e0fd8207a1
commit
77cf757103
@@ -406,19 +406,24 @@ const memberPropertyName = (
|
||||
? `[computed@${String(node.property.start ?? -1)}]`
|
||||
: semanticStaticPropertyName(node.property, node.computed);
|
||||
|
||||
/** Return a string literal value without evaluating an expression. */
|
||||
/**
|
||||
* Return a string literal value without evaluating an expression. A template
|
||||
* literal without substitutions denotes the same exact string.
|
||||
*/
|
||||
export const stringValue = (
|
||||
node: t.Node | null | undefined,
|
||||
): string | undefined => (t.isStringLiteral(node) ? node.value : undefined);
|
||||
): string | undefined => {
|
||||
if (t.isStringLiteral(node)) return node.value;
|
||||
if (t.isTemplateLiteral(node) && node.expressions.length === 0)
|
||||
return node.quasis[0]?.value.cooked ?? undefined;
|
||||
return undefined;
|
||||
};
|
||||
|
||||
/** Return a string or numeric argument literal. */
|
||||
export const argumentValue = (
|
||||
node: t.Node | null | undefined,
|
||||
): string | undefined => {
|
||||
if (t.isStringLiteral(node) || t.isNumericLiteral(node))
|
||||
return String(node.value);
|
||||
return undefined;
|
||||
};
|
||||
): string | undefined =>
|
||||
t.isNumericLiteral(node) ? String(node.value) : stringValue(node);
|
||||
|
||||
/** Prefix a static argument value when one is available. */
|
||||
export const prefixedArgument = (
|
||||
|
||||
Reference in New Issue
Block a user