fix(javascript): preserve initializer execution and lexical ownership

This commit is contained in:
morluto committed 2026-10-24 02:29:44 +08:00
1 parent 5cbcd58550
commit fba4faf88a
8 files changed
+488 -41

No files matched your search

@@ -53,7 +53,6 @@ export const createSemanticExpressionShapeResolver = (
// Most modules have no named child arguments. Collect source-wide blockers
// only when a query actually needs a named binding or ambient undefined.
let blocked: boolean | undefined;
const blockFunctionNames = new Set<string>();
const namedProofBlocked = (): boolean => {
if (blocked !== undefined) return blocked;
blocked = false;
@@ -62,13 +61,6 @@ export const createSemanticExpressionShapeResolver = (
blocked ||=
isErasedJavaScriptDeclaration(node) ||
isUnmodeledJavaScriptRuntimeScope(node);
if (
javaScriptRuntimeContext(state.program) !== "module" &&
t.isFunctionDeclaration(node) &&
node.id != null &&
!hoistedFunction(node)
)
blockFunctionNames.add(node.id.name);
},
});
return blocked;
@@ -105,13 +97,9 @@ export const createSemanticExpressionShapeResolver = (
)
return "unknown";
}
// Annex B may copy a block function into an outer var without an indexed
// assignment. Keep same-named vars unknown rather than model that copy.
if (
namedProofBlocked() ||
semanticOpaqueBindingReadMayHaveChanged(binding, node, state) ||
(binding.declarationKinds.has("var") &&
blockFunctionNames.has(binding.name))
semanticOpaqueBindingReadMayHaveChanged(binding, node, state)
)
return "unknown";
const initializer = semanticStableInitializer(binding, state);