(
node: unknown,
visitor: (
node: Record<string, unknown>,
parent?: Record<string, unknown>,
) => void,
parent?: Record<string, unknown>,
)
| 4 | * Simple recursive AST walker that doesn't require @babel/traverse |
| 5 | */ |
| 6 | export function walkNode( |
| 7 | node: unknown, |
| 8 | visitor: ( |
| 9 | node: Record<string, unknown>, |
| 10 | parent?: Record<string, unknown>, |
| 11 | ) => void, |
| 12 | parent?: Record<string, unknown>, |
| 13 | ): void { |
| 14 | if (!node || typeof node !== 'object') { |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | // Handle arrays |
| 19 | if (Array.isArray(node)) { |
| 20 | for (const child of node) { |
| 21 | walkNode(child, visitor, parent); |
| 22 | } |
| 23 | return; |
| 24 | } |
| 25 | |
| 26 | const nodeObj = node as Record<string, unknown>; |
| 27 | |
| 28 | // Only visit AST nodes (they have a 'type' property) |
| 29 | if (typeof nodeObj.type === 'string') { |
| 30 | visitor(nodeObj, parent); |
| 31 | } |
| 32 | |
| 33 | // Recursively walk all properties |
| 34 | for (const key of Object.keys(nodeObj)) { |
| 35 | const value = nodeObj[key]; |
| 36 | if (value && typeof value === 'object') { |
| 37 | walkNode(value, visitor, nodeObj); |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Track declared variables/parameters to know what identifiers are "local" |
no outgoing calls
no test coverage detected