fix(javascript): correct lexical and dynamic scope analysis (#538)

* fix(javascript): gate CommonJS exports on unshadowed globals and record dynamic scope

* fix(javascript): correct dynamic and switch scope boundaries
This commit is contained in:
morluto
2026-10-05 23:42:48 +08:00
committed by GitHub
parent 00fa97422f
commit 6fa6f1f9b1
13 changed files with 337 additions and 28 deletions
+10
View File
@@ -138,3 +138,13 @@ export const semanticVariableScope = (
}
return candidate;
};
/** Identify a global name only when no lexical or dynamic environment shadows it. */
export const isUnshadowedGlobal = (
node: t.Node,
state: JavaScriptSemanticAnalysisState,
name: string,
): boolean =>
t.isIdentifier(node, { name }) &&
resolveSemanticBindingState(state, node, name) === undefined &&
!semanticResolutionBlocked(state, node, name);