perf(javascript): reuse collected callable identities for returns

This commit is contained in:
morluto committed 2026-10-11 13:20:16 +08:00
1 parent a82d14e4db
commit d3088c3795
2 files changed
+2 -16

No files matched your search

@@ -26,7 +26,6 @@ import {
import { evaluateSemanticExpression } from "./javascriptSemanticValues.js";
import { range } from "./javascriptStaticAnalysisHelpers.js";
import { semanticReturnCoverage } from "./javascriptSemanticCoverage.js";
import { traverseJavaScriptAst } from "./javascriptSemanticTraversal.js";
import { semanticCallableResultExpressions } from "./javascriptSemanticCallableResults.js";
interface ReturnExpression {
@@ -36,13 +35,11 @@ interface ReturnExpression {
/** Evaluate direct returns while excluding every nested callable. */
export const collectSemanticReturns = (
program: t.Program,
state: JavaScriptSemanticAnalysisState,
parserPartial: boolean,
): JavaScriptSemanticCallable[] => {
const nodes = callableNodes(program);
return state.callables.map((callable) => {
const node = nodes.get(callable.callableId);
const node = state.callableNodesById.get(callable.callableId);
if (node === undefined)
return {
...callable,
@@ -117,17 +114,6 @@ export const resolveSemanticModuleCallables = (
});
};
const callableNodes = (program: t.Program): Map<string, t.Node> => {
const output = new Map<string, t.Node>();
traverseJavaScriptAst(program, {
enter: (node) => {
const id = semanticCallableIdForNode(node);
if (id !== null) output.set(id, node);
},
});
return output;
};
const directReturnExpressions = (callable: t.Node): ReturnExpression[] =>
semanticCallableResultExpressions(callable)
.filter(({ kind }) => kind === "return")