1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.findNodes = void 0;
|
4 | function findNodes(node, kind, max = Infinity) {
|
5 | if (!node || max == 0) {
|
6 | return [];
|
7 | }
|
8 | const arr = [];
|
9 | const hasMatch = Array.isArray(kind)
|
10 | ? kind.includes(node.kind)
|
11 | : node.kind === kind;
|
12 | if (hasMatch) {
|
13 | arr.push(node);
|
14 | max--;
|
15 | }
|
16 | if (max > 0) {
|
17 | for (const child of node.getChildren()) {
|
18 | findNodes(child, kind, max).forEach((node) => {
|
19 | if (max > 0) {
|
20 | arr.push(node);
|
21 | }
|
22 | max--;
|
23 | });
|
24 | if (max <= 0) {
|
25 | break;
|
26 | }
|
27 | }
|
28 | }
|
29 | return arr;
|
30 | }
|
31 | exports.findNodes = findNodes;
|
32 |
|
\ | No newline at end of file |