mirror of
https://github.com/morluto/rea.git
synced 2026-11-06 23:06:18 +00:00
* fix(javascript)!: preserve operator influence in semantic traces * test(javascript): align semantic influence regressions * style(javascript): format semantic IR * test(javascript): follow literal argument seed influence * fix(javascript): keep one literal node per operator operand Reuse an existing literal for operator influence, and treat TypeScript assertion wrappers as transparent when deciding whether a call result is used. * test(mcp): assert bundle path issues by field compare_bundles reports each relative path as an invalid_format issue instead of one joined diagnostic sentence. * fix(javascript): index operator literals by range and initializer Repeated string operands rescanned every retained literal and every initializer flow. Lookup now uses those indexes, and a 1200-declaration file still projects one literal per operand. * fix(javascript): keep literal and call facts on their own occurrences Operator literals match their own source range, so a nested function does not inherit the enclosing declaration's literal. A direct argument still reaches the call, while the assigned result follows modeled returns. for-loop initializers and updates are discarded call results. * test(javascript): expect conditional operand literals beside binding values A conditional binding keeps one candidate literal per union value and one operator literal per operand token. Those are different facts, so the aggregate payload check counts four nodes and compares literal seeds in query order. * perf(javascript): index call return flows by call site projectCalls filtered every call return for each assigned result. Group those flows once while projecting returns-to-call edges. --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
89 lines
3.5 KiB
TypeScript
89 lines
3.5 KiB
TypeScript
import { moduleResolutionModeForJavaScriptReference } from "../domain/javascript/javascriptModuleResolutionMode.js";
|
|
import { parseJavaScriptSource } from "../domain/javascript/javascriptSourceParser.js";
|
|
import { analyzeParsedJavaScriptStaticSourceSteps } from "../domain/javascript/javascriptStaticAnalysis.js";
|
|
import { analyzeParsedJavaScriptSemanticsSteps } from "../domain/javascript/javascriptSemanticAnalysis.js";
|
|
import { failedJavaScriptStaticAnalysis } from "../domain/javascript/javascriptStaticAnalysisHelpers.js";
|
|
import { projectJavaScriptModuleSemantics } from "../domain/javascript/javascriptModuleSemanticIr.js";
|
|
import {
|
|
javaScriptTransferByteBudget,
|
|
measureJavaScriptModuleTransfer,
|
|
} from "../javascript/analysis/JavaScriptAnalysisTransfer.js";
|
|
import { AnalysisResourceConstraintError } from "../domain/analysisErrorCore.js";
|
|
import { projectJavaScriptSemanticFileSteps } from "../application/javascript/JavaScriptSemanticGraphBuilder.js";
|
|
import { completeJavaScriptAnalysisSteps } from "../application/javascript/JavaScriptAnalysisControl.js";
|
|
import {
|
|
serveJavaScriptAnalysisWorker,
|
|
type JavaScriptSourceWorkerAnalyzer,
|
|
} from "../javascript/analysis/JavaScriptAnalysisWorkerServer.js";
|
|
|
|
const analyze: JavaScriptSourceWorkerAnalyzer = async (
|
|
file,
|
|
capacity,
|
|
callbacks,
|
|
) => {
|
|
if (!file.text.included)
|
|
throw new TypeError("JavaScript worker requires decoded source text");
|
|
await callbacks.phase("parse");
|
|
let parsed = parseJavaScriptSource(file.text.value, file.path);
|
|
if (parsed === null) {
|
|
await callbacks.checkpoint(failedJavaScriptStaticAnalysis());
|
|
return null;
|
|
}
|
|
await callbacks.phase("static");
|
|
const facts = await completeJavaScriptAnalysisSteps(
|
|
analyzeParsedJavaScriptStaticSourceSteps(file.text.value, parsed),
|
|
);
|
|
const resultBudgetBytes = await callbacks.checkpoint(facts);
|
|
if (facts.parse_status === "failed") return null;
|
|
if (resultBudgetBytes === 0)
|
|
throw new AnalysisResourceConstraintError(
|
|
"analyze_javascript_application",
|
|
"memory",
|
|
`The parent reserved its remaining result capacity for static observations; semantic analysis of ${file.path} was not started`,
|
|
{ semantic_result_budget_bytes: 0 },
|
|
);
|
|
await callbacks.phase("semantic");
|
|
const ir = await completeJavaScriptAnalysisSteps(
|
|
analyzeParsedJavaScriptSemanticsSteps(
|
|
parsed,
|
|
moduleResolutionModeForJavaScriptReference(file.path, "static-import"),
|
|
capacity.nodes,
|
|
),
|
|
);
|
|
parsed = null;
|
|
const module = projectJavaScriptModuleSemantics(ir);
|
|
const measured = measureJavaScriptModuleTransfer(
|
|
module,
|
|
javaScriptTransferByteBudget(resultBudgetBytes),
|
|
);
|
|
if (measured.retentionBytes > resultBudgetBytes)
|
|
throw new AnalysisResourceConstraintError(
|
|
"analyze_javascript_application",
|
|
"memory",
|
|
`Completed module facts for ${file.path} exceed the parent's offered result budget; static facts were retained`,
|
|
{
|
|
semantic_result_budget_bytes: resultBudgetBytes,
|
|
module_transfer_bytes: measured.bytes,
|
|
},
|
|
);
|
|
await callbacks.phase("projection");
|
|
const projection = await completeJavaScriptAnalysisSteps(
|
|
projectJavaScriptSemanticFileSteps(
|
|
file,
|
|
ir,
|
|
capacity,
|
|
facts.electron.call_paths,
|
|
),
|
|
);
|
|
return { module, projection };
|
|
};
|
|
|
|
try {
|
|
await serveJavaScriptAnalysisWorker(analyze);
|
|
} catch (cause: unknown) {
|
|
process.stderr.write(
|
|
`${cause instanceof Error ? cause.message : String(cause)}\n`,
|
|
);
|
|
process.exitCode = 1;
|
|
}
|