mirror of
https://github.com/morluto/rea
synced 2026-10-27 14:42:18 -04:00
fix(javascript): preserve values captured before later assignments (#4196)
Select binding facts at reads without mixing whole-binding and temporal values. Share conditional activation rules, preserve partial expression order, and bound immutable ancestry work. Memoize temporal results within each query using initializer identity, capture point, budget and dependency proofs; preserve depth limits and source Evidence. Fixes #3881
This commit is contained in:
@@ -33,19 +33,37 @@ const ancestryReads = (
|
||||
}
|
||||
};
|
||||
|
||||
it("bounds ancestry reads for repeated deep lexical references", () => {
|
||||
it.each(["const a=1;", "let a; a=1;"])(
|
||||
"bounds ancestry reads for repeated deep lexical references after %s",
|
||||
(declaration) => {
|
||||
const reads = (depth: number): number =>
|
||||
ancestryReads(
|
||||
`${declaration} module.exports.value=${"a+(".repeat(depth)}a${")".repeat(depth)};`,
|
||||
(ir) => {
|
||||
expect(ir.coverage).toEqual({ status: "complete", omittedCount: 0 });
|
||||
expect(onlyBinding(ir, "a").value).toEqual({
|
||||
status: "literal",
|
||||
value: 1,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
const smaller = reads(80);
|
||||
const larger = reads(160);
|
||||
expect(smaller).toBeGreaterThan(0);
|
||||
expect(larger).toBeLessThan(3 * smaller);
|
||||
},
|
||||
);
|
||||
|
||||
it("bounds ancestry reads after a write in the same expression", () => {
|
||||
const reads = (depth: number): number =>
|
||||
ancestryReads(
|
||||
`const a=1; module.exports.value=${"a+(".repeat(depth)}a${")".repeat(depth)};`,
|
||||
`let a=0; module.exports.value={set:(a=1),value:${"a+(".repeat(depth)}a${")".repeat(depth)}};`,
|
||||
(ir) => {
|
||||
expect(ir.coverage).toEqual({ status: "complete", omittedCount: 0 });
|
||||
expect(onlyBinding(ir, "a").value).toEqual({
|
||||
status: "literal",
|
||||
value: 1,
|
||||
});
|
||||
expect(onlyBinding(ir, "a").value.status).toBe("ambiguous");
|
||||
},
|
||||
);
|
||||
|
||||
const smaller = reads(80);
|
||||
const larger = reads(160);
|
||||
expect(smaller).toBeGreaterThan(0);
|
||||
|
||||
Reference in New Issue
Block a user