MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / findDescendant

Function findDescendant

src/extraction/languages/lua.ts:9–17  ·  view source on GitHub ↗

First descendant of a given type (breadth-first), or null.

(node: SyntaxNode, type: string)

Source from the content-addressed store, hash-verified

7
8/** First descendant of a given type (breadth-first), or null. */
9function findDescendant(node: SyntaxNode, type: string): SyntaxNode | null {
10 const queue: SyntaxNode[] = [...node.namedChildren];
11 while (queue.length) {
12 const n = queue.shift()!;
13 if (n.type === type) return n;
14 queue.push(...n.namedChildren);
15 }
16 return null;
17}
18
19/**
20 * If `callNode` is a `require(...)` call, return the module name; otherwise null.

Callers 1

requireModuleFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected