mirror of
https://github.com/morluto/rea.git
synced 2026-11-03 05:16:16 +00:00
Cache direct return/yield source expressions by immutable AST identity for all existing static and semantic consumers. Weak keys bound retention to AST lifetime; mutable analysis facts and Evidence remain unchanged. Refs #6311; full CastleIO analysis still times out. Validation: 225 focused tests; baseline cache-regression controls; build, serial check:fast and test discovery passed. CastleIO direct-syntax facts equal with 78,272 warm lookups reduced from 2.72-2.81s to 13.0-13.4ms. Complete sourcemap-codec CLI analyses retained byte-identical Evidence; no end-to-end speedup or token reduction claimed. CI: source 20,888 passed / 15 skipped; seven built-dependent shards, static, docs, package builds, Linux native baseline and real JS recovery CLI/MCP passed. Shard 6 Hermes path-preview failures both reproduce on exact main b9d1a61dd; Portable tests fails downstream. Greptile 5/5, no findings; Codex quota exhausted. Authorized admin bypass for unrelated baseline CI and unchecked human readiness; no human review attestation made.
70 lines
2.5 KiB
TypeScript
70 lines
2.5 KiB
TypeScript
import * as t from "@babel/types";
|
|
import { expect, it } from "vitest";
|
|
import { semanticCallableResultExpressions } from "./javascriptSemanticCallableResults.js";
|
|
import { parseJavaScriptSource } from "./javascriptSourceParser.js";
|
|
|
|
it("reuses direct result syntax while excluding nested callable results", () => {
|
|
const parsed = parseJavaScriptSource(`function* outer(){
|
|
function inner(){return hidden;}
|
|
class Hidden{method(){return hidden;}}
|
|
if(flag)return first;
|
|
yield* second;
|
|
}`);
|
|
const callable = parsed?.program.body[0];
|
|
if (!t.isFunctionDeclaration(callable))
|
|
throw new Error("Expected callable fixture");
|
|
const statements = callable.body.body;
|
|
let reads = 0;
|
|
Object.defineProperty(callable.body, "body", {
|
|
get: () => {
|
|
reads += 1;
|
|
return statements;
|
|
},
|
|
});
|
|
const result = semanticCallableResultExpressions(callable);
|
|
expect(
|
|
result.map(({ node, kind, delegated }) => [
|
|
t.isIdentifier(node) ? node.name : null,
|
|
kind,
|
|
delegated,
|
|
]),
|
|
).toEqual([
|
|
["first", "return", false],
|
|
["second", "yield", true],
|
|
]);
|
|
expect(reads).toBeGreaterThan(0);
|
|
reads = 0;
|
|
for (let i = 0; i < 32; i++)
|
|
expect(semanticCallableResultExpressions(callable)).toBe(result);
|
|
expect(reads).toBe(0);
|
|
});
|
|
|
|
it("keeps identical source text in separate syntax trees distinct", () => {
|
|
const first = t.arrowFunctionExpression([], t.identifier("value"));
|
|
const second = t.arrowFunctionExpression([], t.identifier("value"));
|
|
expect(semanticCallableResultExpressions(first)[0]?.node).toBe(first.body);
|
|
expect(semanticCallableResultExpressions(second)[0]?.node).toBe(second.body);
|
|
});
|
|
|
|
it("retains empty results and bare return/yield source sites", () => {
|
|
const empty = t.functionExpression(null, [], t.blockStatement([]));
|
|
const emptyResult = semanticCallableResultExpressions(empty);
|
|
expect(emptyResult).toEqual([]);
|
|
expect(semanticCallableResultExpressions(empty)).toBe(emptyResult);
|
|
|
|
const bareReturn = t.returnStatement();
|
|
const bareYield = t.yieldExpression();
|
|
const generator = t.functionExpression(
|
|
null,
|
|
[],
|
|
t.blockStatement([t.expressionStatement(bareYield), bareReturn]),
|
|
true,
|
|
);
|
|
const result = semanticCallableResultExpressions(generator);
|
|
expect(result).toEqual([
|
|
{ node: null, site: bareYield, kind: "yield", delegated: false },
|
|
{ node: null, site: bareReturn, kind: "return", delegated: false },
|
|
]);
|
|
expect(semanticCallableResultExpressions(generator)).toBe(result);
|
|
});
|