MCPcopy Create free account
hub / github.com/angular/angular / findFirstMatchingNode

Function findFirstMatchingNode

packages/language-service/src/utils/ts_utils.ts:61–83  ·  view source on GitHub ↗
(
  root: ts.Node,
  opts: FindOptions<T>,
)

Source from the content-addressed store, hash-verified

59 * Finds TypeScript nodes descending from the provided root which match the given filter.
60 */
61export 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.

Calls 1

exploreFunction · 0.85

Tested by

no test coverage detected