|
| 1 | +/** |
| 2 | + * Options for the Visitor constructor and visit function. |
| 3 | + */ |
| 4 | +interface VisitorOptions { |
| 5 | + /** |
| 6 | + * Fallback strategy for unknown node types. |
| 7 | + * @default 'iteration' |
| 8 | + */ |
| 9 | + fallback?: "iteration" | ((node: any) => string[]); |
| 10 | + |
| 11 | + /** |
| 12 | + * Custom keys for child nodes by node type. |
| 13 | + * @default {} |
| 14 | + */ |
| 15 | + childVisitorKeys?: Record<string, string[]>; |
| 16 | +} |
| 17 | + |
| 18 | +/** |
| 19 | + * A visitor class for recursively traversing ECMAScript AST. |
| 20 | + */ |
| 21 | +declare class Visitor { |
| 22 | + /** |
| 23 | + * Creates a new Visitor instance. |
| 24 | + * @param options Configuration options for the visitor. |
| 25 | + */ |
| 26 | + constructor(visitor?: Visitor | null, options?: VisitorOptions | null); |
| 27 | + |
| 28 | + /** |
| 29 | + * Visits a node, invoking the appropriate handler. |
| 30 | + * @param node The AST node to visit. |
| 31 | + */ |
| 32 | + visit(node: any): void; |
| 33 | + |
| 34 | + /** |
| 35 | + * Visits the children of a node based on childVisitorKeys. |
| 36 | + * @param node The AST node whose children to visit. |
| 37 | + */ |
| 38 | + visitChildren(node: any): void; |
| 39 | + |
| 40 | + /** |
| 41 | + * Dynamically defined methods for specific node types (e.g., Literal, Program). |
| 42 | + * @param node The AST node to process. |
| 43 | + */ |
| 44 | + [nodeType: string]: ((node: any) => void) | undefined; |
| 45 | +} |
| 46 | + |
| 47 | +/** |
| 48 | + * Visits an AST node with the specified visitor. |
| 49 | + * @param ast The AST node to traverse. |
| 50 | + * @param visitor A visitor instance or visitor object. |
| 51 | + * @param options Configuration options for the traversal. |
| 52 | + */ |
| 53 | +declare function visit( |
| 54 | + ast: any, |
| 55 | + visitor?: Visitor | Record<string, (node: any) => void> | null, |
| 56 | + options?: VisitorOptions, |
| 57 | +): void; |
| 58 | + |
| 59 | +export { visit, Visitor, type VisitorOptions }; |
0 commit comments