| 109 | } |
| 110 | |
| 111 | function walk(node: unknown, visit: (n: { type: string }) => void): void { |
| 112 | if (!node || typeof node !== 'object') { return; } |
| 113 | const typed = node as { type?: string }; |
| 114 | if (typeof typed.type === 'string') { |
| 115 | visit(typed as { type: string }); |
| 116 | } |
| 117 | for (const key of Object.keys(node)) { |
| 118 | if (key === 'parent') { continue; } |
| 119 | const value = (node as Record<string, unknown>)[key]; |
| 120 | if (Array.isArray(value)) { |
| 121 | for (const v of value) { walk(v, visit); } |
| 122 | } else if (value && typeof value === 'object' && typeof (value as { type?: string }).type === 'string') { |
| 123 | walk(value, visit); |
| 124 | } |
| 125 | } |
| 126 | } |