nodeIndex
tcmts.core.analyze.nodeIndex · #b35ygxq6 · term · runs anywhere
import { indexes } from "#codebase/tcmts/core/analyze";
import type { Node as ts_Node, SourceFile as ts_SourceFile } from "typescript/ast";
export function nodeIndex(sf: ts_SourceFile): Map<number, ts_Node> {
let m = indexes.get(sf);
if (!m) {
const out = new Map<number, ts_Node>();
const walk = (n: ts_Node) => {
out.set((n as unknown as { index: number }).index, n);
n.forEachChild(walk, (arr) => void arr.forEach(walk));
};
walk(sf);
indexes.set(sf, (m = out));
}
return m;
}
uses
used by