( root: TSESTree.Node | TSESTree.Node[], visit: (node: TSESTree.Node, parent: TSESTree.Node | null) => void )
| 561 | } |
| 562 | |
| 563 | function walkAst( |
| 564 | root: TSESTree.Node | TSESTree.Node[], |
| 565 | visit: (node: TSESTree.Node, parent: TSESTree.Node | null) => void |
| 566 | ): void { |
| 567 | const pending: Array<{ node: TSESTree.Node; parent: TSESTree.Node | null }> = []; |
| 568 | if (Array.isArray(root)) { |
| 569 | for (const node of root) { |
| 570 | pending.push({ node, parent: null }); |
| 571 | } |
| 572 | } else { |
| 573 | pending.push({ node: root, parent: null }); |
| 574 | } |
| 575 | |
| 576 | const visited = new Set<TSESTree.Node>(); |
| 577 | while (pending.length > 0) { |
| 578 | const next = pending.pop(); |
| 579 | if (!next || visited.has(next.node)) { |
| 580 | continue; |
| 581 | } |
| 582 | visited.add(next.node); |
| 583 | visit(next.node, next.parent); |
| 584 | |
| 585 | for (const child of getChildNodes(next.node)) { |
| 586 | pending.push({ node: child, parent: next.node }); |
| 587 | } |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | function getChildNodes(node: TSESTree.Node): TSESTree.Node[] { |
| 592 | const children: TSESTree.Node[] = []; |
no test coverage detected