fix(browser): preserve evidence through deep AST analysis (#924)

This commit is contained in:
morluto
2026-10-07 18:36:18 +08:00
committed by GitHub
parent 28fd49f0f6
commit f826aa893f
8 changed files with 202 additions and 79 deletions
@@ -92,16 +92,22 @@ export const collectSemanticModuleLink = (
else if (t.isAssignmentExpression(node)) collectCommonJsExport(node, state);
};
/** Collect bounded lexical identifier references after definitions exist. */
/** Collect lexical references after definitions exist, optionally for one name. */
export const collectSemanticReferences = (
program: t.Program,
state: JavaScriptSemanticAnalysisState,
name?: string,
): JavaScriptSemanticReference[] => {
const output: JavaScriptSemanticReference[] = [];
const seen = new Set<string>();
traverseJavaScriptAst(program, {
enter: (node, parent, readAncestors) => {
if (!t.isIdentifier(node) || parent === null) return;
if (
!t.isIdentifier(node) ||
parent === null ||
(name !== undefined && node.name !== name)
)
return;
const role = semanticIdentifierRole(node, parent, readAncestors());
if (role === null) return;
// A compound assignment or update reads before it writes; emit both so