|
1 |
| -import acorn from 'acorn'; |
| 1 | +import {Node} from 'acorn'; |
2 | 2 |
|
3 | 3 | declare module "acorn-walk" {
|
4 |
| - type NodeType = acorn.Node["type"]; |
5 |
| - |
6 | 4 | type FullWalkerCallback<TState> = (
|
7 |
| - node: acorn.Node, |
8 |
| - state: TState, |
9 |
| - type: NodeType |
| 5 | + node: Node, |
| 6 | + state: TState, |
| 7 | + type: string |
10 | 8 | ) => void;
|
11 | 9 |
|
12 | 10 | type FullAncestorWalkerCallback<TState> = (
|
13 |
| - node: acorn.Node, |
14 |
| - state: TState | acorn.Node[], |
15 |
| - ancestors: acorn.Node[], |
16 |
| - type: NodeType |
| 11 | + node: Node, |
| 12 | + state: TState | Node[], |
| 13 | + ancestors: Node[], |
| 14 | + type: string |
17 | 15 | ) => void;
|
18 |
| - type WalkerCallback<TState> = (node: acorn.Node, state: TState) => void; |
| 16 | + type WalkerCallback<TState> = (node: Node, state: TState) => void; |
19 | 17 |
|
20 |
| - type SimpleWalkerFn<K extends NodeType, TState> = ( |
21 |
| - node: acorn.Node, |
22 |
| - state: TState |
| 18 | + type SimpleWalkerFn<TState> = ( |
| 19 | + node: Node, |
| 20 | + state: TState |
23 | 21 | ) => void;
|
24 | 22 |
|
25 |
| - type AncestorWalkerFn<K extends NodeType, TState> = ( |
26 |
| - node: acorn.Node, |
27 |
| - state: TState| acorn.Node[], |
28 |
| - ancestors: acorn.Node[] |
| 23 | + type AncestorWalkerFn<TState> = ( |
| 24 | + node: Node, |
| 25 | + state: TState| Node[], |
| 26 | + ancestors: Node[] |
29 | 27 | ) => void;
|
30 | 28 |
|
31 |
| - type RecursiveWalkerFn<K extends NodeType, TState> = ( |
32 |
| - node: acorn.Node, |
33 |
| - state: TState, |
34 |
| - callback: WalkerCallback<TState> |
| 29 | + type RecursiveWalkerFn<TState> = ( |
| 30 | + node: Node, |
| 31 | + state: TState, |
| 32 | + callback: WalkerCallback<TState> |
35 | 33 | ) => void;
|
36 | 34 |
|
37 |
| - type SimpleVisitors<Types extends NodeType, TState> = { |
38 |
| - [Type in Types]: SimpleWalkerFn<Type, TState> |
| 35 | + type SimpleVisitors<TState> = { |
| 36 | + [type: string]: SimpleWalkerFn<TState> |
39 | 37 | };
|
40 | 38 |
|
41 |
| - type AncestorVisitors<Types extends NodeType, TState> = { |
42 |
| - [Type in Types]: AncestorWalkerFn<Type, TState> |
| 39 | + type AncestorVisitors<TState> = { |
| 40 | + [type: string]: AncestorWalkerFn<TState> |
43 | 41 | };
|
44 | 42 |
|
45 |
| - type RecursiveVisitors<Types extends NodeType, TState> = { |
46 |
| - [Type in Types]: RecursiveWalkerFn<Type, TState> |
| 43 | + type RecursiveVisitors<TState> = { |
| 44 | + [type: string]: RecursiveWalkerFn<TState> |
47 | 45 | };
|
48 | 46 |
|
49 |
| - type FindPredicate = (type: NodeType, node: acorn.Node) => boolean; |
| 47 | + type FindPredicate = (type: string, node: Node) => boolean; |
50 | 48 |
|
51 |
| - interface Found<Type extends NodeType, TState> { |
52 |
| - node: acorn.Node, |
53 |
| - state: TState |
| 49 | + interface Found<TState> { |
| 50 | + node: Node, |
| 51 | + state: TState |
54 | 52 | }
|
55 | 53 |
|
56 |
| - export function simple<TState, K extends NodeType>( |
57 |
| - node: acorn.Node, |
58 |
| - visitors: SimpleVisitors<K, TState>, |
59 |
| - base?: RecursiveVisitors<NodeType, TState>, |
60 |
| - state?: TState |
| 54 | + export function simple<TState>( |
| 55 | + node: Node, |
| 56 | + visitors: SimpleVisitors<TState>, |
| 57 | + base?: RecursiveVisitors<TState>, |
| 58 | + state?: TState |
61 | 59 | ): void;
|
62 | 60 |
|
63 |
| - export function ancestor<TState, K extends NodeType>( |
64 |
| - node: acorn.Node, |
65 |
| - visitors: AncestorVisitors<K, TState>, |
66 |
| - base?: RecursiveVisitors<NodeType, TState>, |
67 |
| - state?: TState |
| 61 | + export function ancestor<TState>( |
| 62 | + node: Node, |
| 63 | + visitors: AncestorVisitors<TState>, |
| 64 | + base?: RecursiveVisitors<TState>, |
| 65 | + state?: TState |
68 | 66 | ): void;
|
69 | 67 |
|
70 |
| - export function recursive<TState, K extends NodeType>( |
71 |
| - node: acorn.Node, |
72 |
| - state: TState, |
73 |
| - functions: RecursiveVisitors<K, TState>, |
74 |
| - base?: RecursiveVisitors<NodeType, TState> |
| 68 | + export function recursive<TState>( |
| 69 | + node: Node, |
| 70 | + state: TState, |
| 71 | + functions: RecursiveVisitors<TState>, |
| 72 | + base?: RecursiveVisitors<TState> |
75 | 73 | ): void;
|
76 | 74 |
|
77 | 75 | export function full<TState>(
|
78 |
| - node: acorn.Node, |
79 |
| - callback: FullWalkerCallback<TState>, |
80 |
| - base?: RecursiveVisitors<NodeType, TState>, |
81 |
| - state?: TState |
| 76 | + node: Node, |
| 77 | + callback: FullWalkerCallback<TState>, |
| 78 | + base?: RecursiveVisitors<TState>, |
| 79 | + state?: TState |
82 | 80 | ): void;
|
83 | 81 |
|
84 | 82 | export function fullAncestor<TState>(
|
85 |
| - node: acorn.Node, |
86 |
| - callback: FullAncestorWalkerCallback<TState>, |
87 |
| - base?: RecursiveVisitors<NodeType, TState>, |
88 |
| - state?: TState |
| 83 | + node: Node, |
| 84 | + callback: FullAncestorWalkerCallback<TState>, |
| 85 | + base?: RecursiveVisitors<TState>, |
| 86 | + state?: TState |
89 | 87 | ): void;
|
90 | 88 |
|
91 |
| - export function make<TState, K extends NodeType>( |
92 |
| - functions: RecursiveVisitors<K, TState>, |
93 |
| - base?: RecursiveVisitors<NodeType, TState> |
94 |
| - ): RecursiveVisitors<NodeType, TState>; |
| 89 | + export function make<TState>( |
| 90 | + functions: RecursiveVisitors<TState>, |
| 91 | + base?: RecursiveVisitors<TState> |
| 92 | + ): RecursiveVisitors<TState>; |
95 | 93 |
|
96 |
| - export function findNodeAt<TState, K extends NodeType>( |
97 |
| - node: acorn.Node, |
98 |
| - start: number | undefined, |
99 |
| - end: number | undefined, |
100 |
| - type: K, |
101 |
| - base?: RecursiveVisitors<NodeType, TState>, |
102 |
| - state?: TState |
103 |
| - ): Found<K, TState> | undefined; |
| 94 | + export function findNodeAt<TState>( |
| 95 | + node: Node, |
| 96 | + start: number | undefined, |
| 97 | + end: number | undefined, |
| 98 | + type: string, |
| 99 | + base?: RecursiveVisitors<TState>, |
| 100 | + state?: TState |
| 101 | + ): Found<TState> | undefined; |
104 | 102 |
|
105 | 103 | export function findNodeAt<TState>(
|
106 |
| - node: acorn.Node, |
107 |
| - start: number | undefined, |
108 |
| - end: number | undefined, |
109 |
| - type?: FindPredicate, |
110 |
| - base?: RecursiveVisitors<NodeType, TState>, |
111 |
| - state?: TState |
112 |
| - ): Found<NodeType, TState> | undefined; |
| 104 | + node: Node, |
| 105 | + start: number | undefined, |
| 106 | + end: number | undefined, |
| 107 | + type?: FindPredicate, |
| 108 | + base?: RecursiveVisitors<TState>, |
| 109 | + state?: TState |
| 110 | + ): Found<TState> | undefined; |
113 | 111 |
|
114 | 112 | export const findNodeAround: typeof findNodeAt;
|
115 | 113 |
|
|
0 commit comments