(cg: CodeGraph, constName: string)
| 12 | import CodeGraph from '../src'; |
| 13 | |
| 14 | function 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 | |
| 31 | describe('value-reference edges', () => { |
| 32 | let dir: string; |
no test coverage detected