Skip to content

Commit 7fba472

Browse files
feat: export visitor object types (#7)
1 parent 667f5a7 commit 7fba472

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

src/index.ts

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,19 @@ export type SimpleFunction<TKey extends string, TState> = (
2828
node: NodeType<TKey>,
2929
state: TState,
3030
) => void;
31+
32+
export type SimpleVisitors<TState = void> = {
33+
[key in keyof t.Aliases | t.Node['type']]?:
34+
| SimpleFunction<key, TState>
35+
| {
36+
enter?: SimpleFunction<key, TState>;
37+
exit?: SimpleFunction<key, TState>;
38+
};
39+
};
40+
3141
export function simple<TState>(
3242
node: t.Node,
33-
visitors: {
34-
[key in keyof t.Aliases | t.Node['type']]?:
35-
| SimpleFunction<key, TState>
36-
| {
37-
enter?: SimpleFunction<key, TState>;
38-
exit?: SimpleFunction<key, TState>;
39-
};
40-
},
43+
visitors: SimpleVisitors<TState>,
4144
state: TState,
4245
) {
4346
const vis = explode(visitors);
@@ -76,16 +79,19 @@ export type AncestorFunction<TKey extends string, TState> = (
7679
state: TState,
7780
ancestors: t.Node[],
7881
) => void;
79-
export function ancestor<TState>(
82+
83+
export type AncestorVisitor<TState = void> = {
84+
[key in keyof t.Aliases | t.Node['type']]?:
85+
| AncestorFunction<key, TState>
86+
| {
87+
enter?: AncestorFunction<key, TState>;
88+
exit?: AncestorFunction<key, TState>;
89+
};
90+
};
91+
92+
export function ancestor<TState = void>(
8093
node: t.Node,
81-
visitors: {
82-
[key in keyof t.Aliases | t.Node['type']]?:
83-
| AncestorFunction<key, TState>
84-
| {
85-
enter?: AncestorFunction<key, TState>;
86-
exit?: AncestorFunction<key, TState>;
87-
};
88-
},
94+
visitors: AncestorVisitor<TState>,
8995
state: TState,
9096
) {
9197
const vis = explode(visitors);
@@ -126,15 +132,17 @@ export function ancestor<TState>(
126132
})(node);
127133
}
128134

135+
export type RecursiveVisitors<TState = void> = {
136+
[key in keyof t.Aliases | t.Node['type']]?: (
137+
node: NodeType<key>,
138+
state: TState,
139+
recurse: (node: t.Node) => void,
140+
) => void;
141+
};
142+
129143
export function recursive<TState>(
130144
node: t.Node,
131-
visitors: {
132-
[key in keyof t.Aliases | t.Node['type']]?: (
133-
node: NodeType<key>,
134-
state: TState,
135-
recurse: (node: t.Node) => void,
136-
) => void;
137-
},
145+
visitors: RecursiveVisitors<TState>,
138146
state: TState,
139147
) {
140148
const vis = explode(visitors);

0 commit comments

Comments
 (0)