MCPcopy Create free account
hub / github.com/PatrickSys/codebase-context / walkAst

Function walkAst

src/analyzers/react/index.ts:563–589  ·  view source on GitHub ↗
(
  root: TSESTree.Node | TSESTree.Node[],
  visit: (node: TSESTree.Node, parent: TSESTree.Node | null) => void
)

Source from the content-addressed store, hash-verified

561}
562
563function 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
591function getChildNodes(node: TSESTree.Node): TSESTree.Node[] {
592 const children: TSESTree.Node[] = [];

Callers 2

summarizeReactProgramFunction · 0.85
containsJsxFunction · 0.85

Calls 3

getChildNodesFunction · 0.85
hasMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected