Skip to content

Commit e9372c1

Browse files
committed
Further clean up walker types
1 parent de6edeb commit e9372c1

File tree

1 file changed

+72
-74
lines changed

1 file changed

+72
-74
lines changed

acorn-walk/dist/walk.d.ts

+72-74
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,113 @@
1-
import acorn from 'acorn';
1+
import {Node} from 'acorn';
22

33
declare module "acorn-walk" {
4-
type NodeType = acorn.Node["type"];
5-
64
type FullWalkerCallback<TState> = (
7-
node: acorn.Node,
8-
state: TState,
9-
type: NodeType
5+
node: Node,
6+
state: TState,
7+
type: string
108
) => void;
119

1210
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
1715
) => void;
18-
type WalkerCallback<TState> = (node: acorn.Node, state: TState) => void;
16+
type WalkerCallback<TState> = (node: Node, state: TState) => void;
1917

20-
type SimpleWalkerFn<K extends NodeType, TState> = (
21-
node: acorn.Node,
22-
state: TState
18+
type SimpleWalkerFn<TState> = (
19+
node: Node,
20+
state: TState
2321
) => void;
2422

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[]
2927
) => void;
3028

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>
3533
) => void;
3634

37-
type SimpleVisitors<Types extends NodeType, TState> = {
38-
[Type in Types]: SimpleWalkerFn<Type, TState>
35+
type SimpleVisitors<TState> = {
36+
[type: string]: SimpleWalkerFn<TState>
3937
};
4038

41-
type AncestorVisitors<Types extends NodeType, TState> = {
42-
[Type in Types]: AncestorWalkerFn<Type, TState>
39+
type AncestorVisitors<TState> = {
40+
[type: string]: AncestorWalkerFn<TState>
4341
};
4442

45-
type RecursiveVisitors<Types extends NodeType, TState> = {
46-
[Type in Types]: RecursiveWalkerFn<Type, TState>
43+
type RecursiveVisitors<TState> = {
44+
[type: string]: RecursiveWalkerFn<TState>
4745
};
4846

49-
type FindPredicate = (type: NodeType, node: acorn.Node) => boolean;
47+
type FindPredicate = (type: string, node: Node) => boolean;
5048

51-
interface Found<Type extends NodeType, TState> {
52-
node: acorn.Node,
53-
state: TState
49+
interface Found<TState> {
50+
node: Node,
51+
state: TState
5452
}
5553

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
6159
): void;
6260

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
6866
): void;
6967

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>
7573
): void;
7674

7775
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
8280
): void;
8381

8482
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
8987
): void;
9088

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>;
9593

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;
104102

105103
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;
113111

114112
export const findNodeAround: typeof findNodeAt;
115113

0 commit comments

Comments
 (0)