(closure: ClosureDocument)
| 94 | * timeline of calls and not a set of symbols. |
| 95 | */ |
| 96 | export function flowNodes(closure: ClosureDocument): FlowNode[] { |
| 97 | const symbols = new Map<string, SymbolRef>(); |
| 98 | for (const symbol of closure.symbols) { |
| 99 | symbols.set(identityOf(symbol), symbol); |
| 100 | } |
| 101 | const outgoing = adjacencyOf(closure.edges); |
| 102 | const out: FlowNode[] = []; |
| 103 | const rootKey = identityOf(closure.root); |
| 104 | |
| 105 | const walk = (from: string, path: readonly string[], depth: number): void => { |
| 106 | for (const to of outgoing.get(from) ?? []) { |
| 107 | if (out.length >= FLOW_NODE_CAP) { |
| 108 | return; |
| 109 | } |
| 110 | const ref = symbols.get(to); |
| 111 | if (ref === undefined) { |
| 112 | continue; |
| 113 | } |
| 114 | const cycle = path.includes(to); |
| 115 | const next = cycle ? path : [...path, to]; |
| 116 | out.push({ |
| 117 | kind: 'symbol', |
| 118 | id: `flow.${out.length}`, |
| 119 | ref, |
| 120 | badges: cycle ? { cycle: true } : {}, |
| 121 | depth, |
| 122 | path: next, |
| 123 | // Nothing here looked up whether the symbol is test code or |
| 124 | // whether the step constructs a class, so nothing here claims to |
| 125 | // have. The badges a closure can support are the cycle and |
| 126 | // nothing else. |
| 127 | enriched: false, |
| 128 | }); |
| 129 | if (!cycle) { |
| 130 | walk(to, next, depth + 1); |
| 131 | } |
| 132 | } |
| 133 | }; |
| 134 | walk(rootKey, [rootKey], 1); |
| 135 | return out; |
| 136 | } |
| 137 | |
| 138 | /** Which symbols each symbol calls, in the order the walk recorded, deduplicated. */ |
| 139 | function adjacencyOf(edges: readonly ClosureEdge[]): Map<string, string[]> { |
no test coverage detected