fix(javascript): separate erased types from runtime semantics

Record erasure during definition indexing and reuse it across runtime references, captures, effects, module links, routes, Electron and Vite. Preserve source type links and emitted decorator and computed-key effects; keep actual runtime reads and escapes conservative.

Validation: 1,647 focused tests and 9 documentation tests passed, with build, static and documentation gates. The inherited reference-lifetimes stress file exhausts a 512 MiB worker on both unmodified 18451e479 and this change; that file remains unverified. TypeScript 7.0.2 emit was inspected for ES2022 and ES2018 without executing emitted code.
This commit is contained in:
morluto committed 2026-10-24 18:00:43 +08:00
1 parent cab78de506
commit 89006609f1
32 files changed
+756 -328

No files matched your search

+106 -94
View File
@@ -17,7 +17,7 @@ import {
STATIC_ROUTE_CALL_NAMES,
stringValue,
} from "./javascriptStaticAnalysisHelpers.js";
import { traverseJavaScriptAstSteps } from "./javascriptSemanticTraversal.js";
import { traverseJavaScriptValueAstSteps } from "./javascriptSemanticTraversal.js";
import {
semanticStableInitializer,
type JavaScriptBindingIndex,
@@ -312,27 +312,33 @@ export class JavaScriptRouteScan {
return;
if (this.#queue(node)) requests.push({ node, site });
};
yield* traverseJavaScriptAstSteps(root, {
skip: () => this.#result.capacity !== null,
enter: (node) => {
if (t.isCallExpression(node) || t.isOptionalCallExpression(node)) {
const parts = calleeName(node.callee).split(".");
if (navigationRecognition(parts.at(-1)!, parts.at(-2) ?? "") !== true)
return;
const first = node.arguments[0];
if (
first !== undefined &&
!t.isSpreadElement(first) &&
!t.isArgumentPlaceholder(first)
yield* traverseJavaScriptValueAstSteps(
root,
this.index.bindings.erasedSyntaxNodes,
{
skip: () => this.#result.capacity !== null,
enter: (node) => {
if (t.isCallExpression(node) || t.isOptionalCallExpression(node)) {
const parts = calleeName(node.callee).split(".");
if (
navigationRecognition(parts.at(-1)!, parts.at(-2) ?? "") !== true
)
return;
const first = node.arguments[0];
if (
first !== undefined &&
!t.isSpreadElement(first) &&
!t.isArgumentPlaceholder(first)
)
remember(first, node);
} else if (
t.isObjectProperty(node) &&
semanticStaticPropertyName(node.key, node.computed) === "href"
)
remember(first, node);
} else if (
t.isObjectProperty(node) &&
semanticStaticPropertyName(node.key, node.computed) === "href"
)
remember(node.value, node);
remember(node.value, node);
},
},
});
);
if (requests.length === 0 || this.#result.capacity !== null) return;
yield* this.index.indexMemberMutationFactsSteps();
for (const { node, site } of requests) {
@@ -384,87 +390,93 @@ export class JavaScriptRouteScan {
structured: true,
reported: true,
};
yield* traverseJavaScriptAstSteps(value, {
skip: (node) =>
this.#result.capacity !== null ||
isRouteValueBoundary(node, true) ||
seen.has(node),
enter: (node, parent) => {
if (node !== value) {
if (!this.#queue(node)) return;
seen.add(node);
}
this.#dynamicValues.set(node, owner);
let overwritten = false;
if (
t.isObjectProperty(node) &&
!isObjectPrototypeSetter(node) &&
t.isObjectExpression(parent)
) {
const key = semanticStaticPropertyKey(node.key, node.computed);
if (key !== null) {
const fields = this.#fields(parent);
const effective = fields.values.get(key);
// Unknown spreads/keys may preserve earlier data. Only a known
// final slot or method proves that this reference was discarded.
overwritten =
fields.dynamicNames.has(key) ||
(effective !== undefined && effective !== node);
yield* traverseJavaScriptValueAstSteps(
value,
this.index.bindings.erasedSyntaxNodes,
{
skip: (node) =>
this.#result.capacity !== null ||
isRouteValueBoundary(node, true) ||
seen.has(node),
enter: (node, parent) => {
if (node !== value) {
if (!this.#queue(node)) return;
seen.add(node);
}
}
const nonValue =
overwritten ||
t.isTSType(node) ||
!isNavigationDataEdge(node, parent) ||
(parent !== null && nonValueReferences.has(parent));
if (nonValue) nonValueReferences.add(node);
if (
!nonValue &&
(t.isMemberExpression(node) || t.isOptionalMemberExpression(node))
) {
for (const selected of this.#memberValues(node)) admit(selected);
}
if (
nonValue ||
!t.isIdentifier(node) ||
(parent !== null && !t.isReferenced(node, parent))
)
return;
const declared = this.index.bindingForReferenceAt(node);
if (declared === undefined) return;
for (const sources of [
declared.initializers,
declared.referenceInitializers,
])
for (const source of sources) if (!this.#queue(source.node)) return;
// Different reads may select different values; unresolved order
// retains its possible sources instead of becoming absence.
const binding = semanticBindingAtRead(
declared,
node,
this.index.bindings.parentsByNode,
).binding;
for (const initializers of [
binding.initializers,
binding.referenceInitializers,
])
for (const initializer of initializers) {
if (
semanticReferenceSourcesInactive(
initializer,
this.index.bindings,
this.#dynamicValues.set(node, owner);
let overwritten = false;
if (
t.isObjectProperty(node) &&
!isObjectPrototypeSetter(node) &&
t.isObjectExpression(parent)
) {
const key = semanticStaticPropertyKey(node.key, node.computed);
if (key !== null) {
const fields = this.#fields(parent);
const effective = fields.values.get(key);
// Unknown spreads/keys may preserve earlier data. Only a known
// final slot or method proves that this reference was discarded.
overwritten =
fields.dynamicNames.has(key) ||
(effective !== undefined && effective !== node);
}
}
const nonValue =
overwritten ||
t.isTSType(node) ||
!isNavigationDataEdge(node, parent) ||
(parent !== null && nonValueReferences.has(parent));
if (nonValue) nonValueReferences.add(node);
if (
!nonValue &&
(t.isMemberExpression(node) || t.isOptionalMemberExpression(node))
) {
for (const selected of this.#memberValues(node)) admit(selected);
}
if (
nonValue ||
!t.isIdentifier(node) ||
(parent !== null && !t.isReferenced(node, parent))
)
return;
const declared = this.index.bindingForReferenceAt(node);
if (declared === undefined) return;
for (const sources of [
declared.initializers,
declared.referenceInitializers,
])
for (const source of sources)
if (!this.#queue(source.node)) return;
// Different reads may select different values; unresolved order
// retains its possible sources instead of becoming absence.
const binding = semanticBindingAtRead(
declared,
node,
this.index.bindings.parentsByNode,
).binding;
for (const initializers of [
binding.initializers,
binding.referenceInitializers,
])
for (const initializer of initializers) {
if (
semanticReferenceSourcesInactive(
initializer,
this.index.bindings,
)
)
)
continue;
for (const selected of this.#initializerValues(initializer))
admit(selected);
}
continue;
for (const selected of this.#initializerValues(initializer))
admit(selected);
}
},
},
});
);
}
}
inspect(node: t.Node, parent: t.Node | null): void {
if (this.index.bindings.erasedSyntaxNodes.has(node)) return;
const expressionParent =
parent === null ? null : (this.#expressionParents.get(parent) ?? parent);
if (