( root: ts.Node, opts: FindOptions<T>, )
| 59 | * Finds TypeScript nodes descending from the provided root which match the given filter. |
| 60 | */ |
| 61 | export function findFirstMatchingNode<T extends ts.Node>( |
| 62 | root: ts.Node, |
| 63 | opts: FindOptions<T>, |
| 64 | ): T | null { |
| 65 | let match: T | null = null; |
| 66 | const explore = (currNode: ts.Node) => { |
| 67 | if (match !== null) { |
| 68 | return; |
| 69 | } |
| 70 | if (opts.position !== undefined) { |
| 71 | if (currNode.getStart() > opts.position || opts.position >= currNode.getEnd()) { |
| 72 | return; |
| 73 | } |
| 74 | } |
| 75 | if (opts.filter(currNode)) { |
| 76 | match = currNode; |
| 77 | return; |
| 78 | } |
| 79 | currNode.forEachChild((descendent) => explore(descendent)); |
| 80 | }; |
| 81 | explore(root); |
| 82 | return match; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Resolves a ClassDeclaration from a SymbolReference. |
no test coverage detected