feat(javascript): discover semantic call literals in feature traces (#7840)

* feat(javascript): discover semantic call literals in feature traces

* fix(javascript): bound retained call literals by transfer capacity

* test(javascript): align feature no-match diagnostic
This commit is contained in:
morluto authored and GitHub committed 2026-10-29 01:25:23 +08:00
1 parent 685f6db960
commit f9e7571a3d
20 files changed
+681 -15

No files matched your search

@@ -0,0 +1,45 @@
import * as t from "@babel/types";
import { expect, it } from "vitest";
import { graphForJavaScript } from "../../../tests/fixtures/javascriptSemanticGraph.js";
import { readExactJavaScriptLiteral } from "./javascriptAstValues.js";
import { analyzeParsedJavaScriptSemantics } from "./javascriptSemanticAnalysis.js";
import { parseJavaScriptSource } from "./javascriptSourceParser.js";
import { queryJavaScriptSemanticGraph } from "./javascriptSemanticQuery.js";
import { javaScriptSemanticQueryInputSchema } from "./javascriptSemanticQuerySchemas.js";
it("recognizes wrapped unary numeric literals without collapsing negative zero", () => {
const wrapped = t.tsAsExpression(t.numericLiteral(7), t.tsNumberKeyword());
expect(readExactJavaScriptLiteral(t.unaryExpression("-", wrapped))).toEqual({
found: true,
value: -7,
});
expect(
readExactJavaScriptLiteral(t.unaryExpression("-", t.numericLiteral(0))),
).toEqual({
found: false,
});
});
it("retains wrapped TypeScript call literals for semantic queries", () => {
const source = "rpc(-(7 as number), +(8 as number), -0, variable);";
const parsed = parseJavaScriptSource(source, "example.ts");
if (parsed === null) throw new Error("Expected TypeScript source to parse");
const graph = graphForJavaScript(
source,
analyzeParsedJavaScriptSemantics(parsed),
);
const call = graph.nodes.find(({ kind }) => kind === "call-site");
expect(call?.properties.arguments).toEqual([
expect.objectContaining({ index: 0, value: -7 }),
expect.objectContaining({ index: 1, value: 8 }),
]);
if (call === undefined) throw new Error("Expected call site");
const result = queryJavaScriptSemanticGraph(
graph,
javaScriptSemanticQueryInputSchema.parse({
seed: { kind: "literal", value: -7 },
direction: "forward-influence",
}),
);
expect(result.seed_node_ids).toContain(call.node_id);
});