mirror of
https://github.com/morluto/rea.git
synced 2026-11-15 11:13:21 +00:00
fix(javascript): unify loader binding and mutation ownership
Model the CommonJS wrapper binding and query shared lexical identity, mutation, and evaluation timing at each call. Remove duplicate importer interpretation and preserve uncertainty for with scopes, prototypes, repeated writes, and opaque object escapes. Validate generated fixtures against bounded Node oracles; no analyzed target execution is added. Refs: #3982, #4072 Co-authored-by: Geronimo <varungore1@gmail.com>
This commit is contained in:
1 parent
b67baede2e
commit
1b9b725c4c
8 files changed
+1089
-295
No files matched your search
@@ -1,9 +1,70 @@
|
||||
import * as t from "@babel/types";
|
||||
|
||||
import { unwrapJavaScriptExpression } from "./javascriptAstValues.js";
|
||||
import {
|
||||
readExactJavaScriptLiteral,
|
||||
semanticStaticPropertyKey,
|
||||
unwrapJavaScriptExpression,
|
||||
} from "./javascriptAstValues.js";
|
||||
|
||||
const preserveGrouping = { stopAtParentheses: true } as const;
|
||||
|
||||
export type JavaScriptSemanticIterationCardinality =
|
||||
| "empty"
|
||||
| "nonempty"
|
||||
| "unknown";
|
||||
|
||||
/** Exact source-only cardinality for literal loop heads. */
|
||||
export const semanticIterationCardinality = (
|
||||
loop: t.ForInStatement | t.ForOfStatement,
|
||||
prototypeMayAffectEnumeration: boolean | undefined,
|
||||
): JavaScriptSemanticIterationCardinality => {
|
||||
const iterable = unwrapJavaScriptExpression(loop.right).node;
|
||||
if (t.isForOfStatement(loop)) {
|
||||
if (prototypeMayAffectEnumeration !== false) return "unknown";
|
||||
if (t.isArrayExpression(iterable)) {
|
||||
if (iterable.elements.length === 0) return "empty";
|
||||
if (
|
||||
iterable.elements.some(
|
||||
(element) => element === null || !t.isSpreadElement(element),
|
||||
)
|
||||
)
|
||||
return "nonempty";
|
||||
return "unknown";
|
||||
}
|
||||
if (t.isStringLiteral(iterable))
|
||||
return iterable.value.length === 0 ? "empty" : "nonempty";
|
||||
return "unknown";
|
||||
}
|
||||
if (t.isObjectExpression(iterable)) {
|
||||
let prototype: t.Node | undefined;
|
||||
for (const property of iterable.properties) {
|
||||
if (t.isSpreadElement(property)) return "unknown";
|
||||
const key = semanticStaticPropertyKey(property.key, property.computed);
|
||||
if (
|
||||
t.isObjectProperty(property) &&
|
||||
!property.computed &&
|
||||
!property.shorthand &&
|
||||
key === "__proto__"
|
||||
) {
|
||||
prototype = unwrapJavaScriptExpression(property.value).node;
|
||||
continue;
|
||||
}
|
||||
if (key === null) return "unknown";
|
||||
return "nonempty";
|
||||
}
|
||||
if (t.isNullLiteral(prototype)) return "empty";
|
||||
if (prototype !== undefined && !readExactJavaScriptLiteral(prototype).found)
|
||||
return "unknown";
|
||||
return prototypeMayAffectEnumeration === false ? "empty" : "unknown";
|
||||
}
|
||||
if (t.isNullLiteral(iterable)) return "empty";
|
||||
if (t.isStringLiteral(iterable) && iterable.value.length > 0)
|
||||
return "nonempty";
|
||||
if (readExactJavaScriptLiteral(iterable).found)
|
||||
return prototypeMayAffectEnumeration === false ? "empty" : "unknown";
|
||||
return "unknown";
|
||||
};
|
||||
|
||||
/** Instance values run on construction; their computed keys run at definition. */
|
||||
export const delayedInstanceFieldValue = (
|
||||
parent: t.Node | undefined,
|
||||
|
||||
Reference in new issue
Block a user