Skip to content

Commit eeb1b73

Browse files
committed
Switch some types on walk.d.ts from Node to AnyNode
FIX: Specify callbacks in acorn-walk's types to receive `AnyNode` type, so that they can be narrowed more easily. Closes #1344
1 parent 5b2e92e commit eeb1b73

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

acorn-walk/src/walk.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import * as acorn from "acorn"
22

33
export type FullWalkerCallback<TState> = (
4-
node: acorn.Node,
4+
node: acorn.AnyNode,
55
state: TState,
66
type: string
77
) => void
88

99
export type FullAncestorWalkerCallback<TState> = (
10-
node: acorn.Node,
10+
node: acorn.AnyNode,
1111
state: TState,
12-
ancestors: acorn.Node[],
12+
ancestors: acorn.AnyNode[],
1313
type: string
1414
) => void
1515

@@ -29,24 +29,24 @@ export type SimpleVisitors<TState> = {
2929
}
3030

3131
export type AncestorVisitors<TState> = {
32-
[type in acorn.AnyNode["type"]]?: ( node: Extract<acorn.AnyNode, { type: type }>, state: TState, ancestors: acorn.Node[]
32+
[type in acorn.AnyNode["type"]]?: ( node: Extract<acorn.AnyNode, { type: type }>, state: TState, ancestors: acorn.AnyNode[]
3333
) => void
3434
} & {
35-
[type in keyof AggregateType]?: (node: AggregateType[type], state: TState, ancestors: acorn.Node[]) => void
35+
[type in keyof AggregateType]?: (node: AggregateType[type], state: TState, ancestors: acorn.AnyNode[]) => void
3636
}
3737

38-
export type WalkerCallback<TState> = (node: acorn.Node, state: TState) => void
38+
export type WalkerCallback<TState> = (node: acorn.AnyNode, state: TState) => void
3939

4040
export type RecursiveVisitors<TState> = {
4141
[type in acorn.AnyNode["type"]]?: ( node: Extract<acorn.AnyNode, { type: type }>, state: TState, callback: WalkerCallback<TState>) => void
4242
} & {
4343
[type in keyof AggregateType]?: (node: AggregateType[type], state: TState, callback: WalkerCallback<TState>) => void
4444
}
4545

46-
export type FindPredicate = (type: string, node: acorn.Node) => boolean
46+
export type FindPredicate = (type: string, node: acorn.AnyNode) => boolean
4747

4848
export interface Found<TState> {
49-
node: acorn.Node,
49+
node: acorn.AnyNode,
5050
state: TState
5151
}
5252

0 commit comments

Comments
 (0)