1 | import { VisitorOption } from "estraverse";
|
2 | import type { Node } from "estree-jsx";
|
3 |
|
4 | export interface Visitor {
|
5 | enter?: (
|
6 | this: EstraverseController,
|
7 | node: Node,
|
8 | parentNode: Node | null
|
9 | ) => VisitorOption | Node | void;
|
10 | leave?: (
|
11 | this: EstraverseController,
|
12 | node: Node,
|
13 | parentNode: Node | null
|
14 | ) => VisitorOption | Node | void;
|
15 | fallback?: "iteration" | ((node: Node) => string[]);
|
16 | keys?: { [nodeType: string]: string[] };
|
17 | }
|
18 |
|
19 | export function traverse(root: Node, visitor: Visitor): void;
|
20 | export function replace(root: Node, visitor: Visitor): Node;
|
21 | export { VisitorOption };
|
22 |
|
23 | export interface EstraverseController {
|
24 | /**
|
25 | * @return property path array from root to current node
|
26 | */
|
27 | path(): string[] | null;
|
28 |
|
29 | /**
|
30 | * @return type of current node
|
31 | */
|
32 | type(): string;
|
33 |
|
34 | /**
|
35 | * @return array of parent elements
|
36 | */
|
37 | parents(): Node[];
|
38 |
|
39 | /**
|
40 | * @return current node
|
41 | */
|
42 | current(): any;
|
43 |
|
44 | /**
|
45 | * skip child nodes of current node
|
46 | */
|
47 | skip(): void;
|
48 |
|
49 | /**
|
50 | * break traversals
|
51 | */
|
52 | break(): void;
|
53 |
|
54 | /**
|
55 | * remove node. available only in replace()
|
56 | */
|
57 | remove(): void;
|
58 | }
|
59 |
|
\ | No newline at end of file |