( kept: WeakMap<readonly Node[], Map<number, Node | null>>, nodesInFile: readonly Node[], line: number, find: () => Node | null, )
| 110 | const ENCLOSING_VALUE = new WeakMap<readonly Node[], Map<number, Node | null>>(); |
| 111 | |
| 112 | function keptByLine( |
| 113 | kept: WeakMap<readonly Node[], Map<number, Node | null>>, |
| 114 | nodesInFile: readonly Node[], |
| 115 | line: number, |
| 116 | find: () => Node | null, |
| 117 | ): Node | null { |
| 118 | // A few nodes are gone through as quickly as an answer is looked up. |
| 119 | if (nodesInFile.length < KEEP_FROM_NODES) return find(); |
| 120 | let byLine = kept.get(nodesInFile); |
| 121 | if (!byLine) { |
| 122 | byLine = new Map(); |
| 123 | kept.set(nodesInFile, byLine); |
| 124 | } |
| 125 | let found = byLine.get(line); |
| 126 | if (found === undefined) { |
| 127 | found = find(); |
| 128 | byLine.set(line, found); |
| 129 | } |
| 130 | return found; |
| 131 | } |
| 132 | |
| 133 | /** Innermost function/method node whose line range contains `line`. */ |
| 134 | export function enclosingFn(nodesInFile: readonly Node[], line: number): Node | null { |
no test coverage detected