MCPcopy
hub / github.com/colbymchenry/codegraph / valueRefReaders

Function valueRefReaders

__tests__/value-reference-edges.test.ts:14–29  ·  view source on GitHub ↗
(cg: CodeGraph, constName: string)

Source from the content-addressed store, hash-verified

12import CodeGraph from '../src';
13
14function valueRefReaders(cg: CodeGraph, constName: string): string[] {
15 // Aggregate across ALL nodes of this name — a conditionally-defined module
16 // const (`try: X=…; except: X=…`) has more than one, and the edge targets
17 // whichever one ended up in the target map.
18 const targets = cg.searchNodes(constName).map((r) => r.node).filter((n) => n.name === constName);
19 const readers = new Set<string>();
20 for (const t of targets) {
21 for (const e of cg.getIncomingEdges(t.id)) {
22 if (e.kind === 'references' && (e.metadata as { valueRef?: boolean } | undefined)?.valueRef) {
23 const r = cg.getNode(e.source)?.name;
24 if (r) readers.add(r);
25 }
26 }
27 }
28 return [...readers];
29}
30
31describe('value-reference edges', () => {
32 let dir: string;

Callers 1

Calls 3

getNodeMethod · 0.80
searchNodesMethod · 0.45
getIncomingEdgesMethod · 0.45

Tested by

no test coverage detected