Skip to content

Commit c86550e

Browse files
nodejs-github-botrichardlau
authored andcommittedApr 26, 2024
deps: update acorn-walk to 8.3.0
PR-URL: #50457 Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
1 parent 9500817 commit c86550e

File tree

6 files changed

+349
-119
lines changed

6 files changed

+349
-119
lines changed
 

‎deps/acorn/acorn-walk/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 8.3.0 (2023-10-26)
2+
3+
### New features
4+
5+
Use a set of new, much more precise, TypeScript types.
6+
17
## 8.2.0 (2021-09-06)
28

39
### New features

‎deps/acorn/acorn-walk/README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ Acorn is open source software released under an
1010

1111
You are welcome to
1212
[report bugs](https://github.com/acornjs/acorn/issues) or create pull
13-
requests on [github](https://github.com/acornjs/acorn). For questions
14-
and discussion, please use the
15-
[Tern discussion forum](https://discuss.ternjs.net).
13+
requests on [github](https://github.com/acornjs/acorn).
1614

1715
## Installation
1816

@@ -68,7 +66,7 @@ const acorn = require("acorn")
6866
const walk = require("acorn-walk")
6967

7068
walk.ancestor(acorn.parse("foo('hi')"), {
71-
Literal(_, ancestors) {
69+
Literal(_node, _state, ancestors) {
7270
console.log("This literal's ancestors are:", ancestors.map(n => n.type))
7371
}
7472
})

‎deps/acorn/acorn-walk/dist/walk.d.mts

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
import * as acorn from "acorn"
2+
3+
export type FullWalkerCallback<TState> = (
4+
node: acorn.Node,
5+
state: TState,
6+
type: string
7+
) => void
8+
9+
export type FullAncestorWalkerCallback<TState> = (
10+
node: acorn.Node,
11+
state: TState,
12+
ancestors: acorn.Node[],
13+
type: string
14+
) => void
15+
16+
type AggregateType = {
17+
Expression: acorn.Expression,
18+
Statement: acorn.Statement,
19+
Pattern: acorn.Pattern,
20+
ForInit: acorn.VariableDeclaration | acorn.Expression
21+
}
22+
23+
export type SimpleVisitors<TState> = {
24+
[type in acorn.AnyNode["type"]]?: (node: Extract<acorn.AnyNode, { type: type }>, state: TState) => void
25+
} & {
26+
[type in keyof AggregateType]?: (node: AggregateType[type], state: TState) => void
27+
}
28+
29+
export type AncestorVisitors<TState> = {
30+
[type in acorn.AnyNode["type"]]?: ( node: Extract<acorn.AnyNode, { type: type }>, state: TState, ancestors: acorn.Node[]
31+
) => void
32+
} & {
33+
[type in keyof AggregateType]?: (node: AggregateType[type], state: TState, ancestors: acorn.Node[]) => void
34+
}
35+
36+
export type WalkerCallback<TState> = (node: acorn.Node, state: TState) => void
37+
38+
export type RecursiveVisitors<TState> = {
39+
[type in acorn.AnyNode["type"]]?: ( node: Extract<acorn.AnyNode, { type: type }>, state: TState, callback: WalkerCallback<TState>) => void
40+
} & {
41+
[type in keyof AggregateType]?: (node: AggregateType[type], state: TState, callback: WalkerCallback<TState>) => void
42+
}
43+
44+
export type FindPredicate = (type: string, node: acorn.Node) => boolean
45+
46+
export interface Found<TState> {
47+
node: acorn.Node,
48+
state: TState
49+
}
50+
51+
/**
52+
* does a 'simple' walk over a tree
53+
* @param node the AST node to walk
54+
* @param visitors an object with properties whose names correspond to node types in the {@link https://github.com/estree/estree | ESTree spec}. The properties should contain functions that will be called with the node object and, if applicable the state at that point.
55+
* @param base a walker algorithm
56+
* @param state a start state. The default walker will simply visit all statements and expressions and not produce a meaningful state. (An example of a use of state is to track scope at each point in the tree.)
57+
*/
58+
export function simple<TState>(
59+
node: acorn.Node,
60+
visitors: SimpleVisitors<TState>,
61+
base?: RecursiveVisitors<TState>,
62+
state?: TState
63+
): void
64+
65+
/**
66+
* does a 'simple' walk over a tree, building up an array of ancestor nodes (including the current node) and passing the array to the callbacks as a third parameter.
67+
* @param node
68+
* @param visitors
69+
* @param base
70+
* @param state
71+
*/
72+
export function ancestor<TState>(
73+
node: acorn.Node,
74+
visitors: AncestorVisitors<TState>,
75+
base?: RecursiveVisitors<TState>,
76+
state?: TState
77+
): void
78+
79+
/**
80+
* does a 'recursive' walk, where the walker functions are responsible for continuing the walk on the child nodes of their target node.
81+
* @param node
82+
* @param state the start state
83+
* @param functions contain an object that maps node types to walker functions
84+
* @param base provides the fallback walker functions for node types that aren't handled in the {@link functions} object. If not given, the default walkers will be used.
85+
*/
86+
export function recursive<TState>(
87+
node: acorn.Node,
88+
state: TState,
89+
functions: RecursiveVisitors<TState>,
90+
base?: RecursiveVisitors<TState>
91+
): void
92+
93+
/**
94+
* does a 'full' walk over a tree, calling the {@link callback} with the arguments (node, state, type) for each node
95+
* @param node
96+
* @param callback
97+
* @param base
98+
* @param state
99+
*/
100+
export function full<TState>(
101+
node: acorn.Node,
102+
callback: FullWalkerCallback<TState>,
103+
base?: RecursiveVisitors<TState>,
104+
state?: TState
105+
): void
106+
107+
/**
108+
* does a 'full' walk over a tree, building up an array of ancestor nodes (including the current node) and passing the array to the callbacks as a third parameter.
109+
* @param node
110+
* @param callback
111+
* @param base
112+
* @param state
113+
*/
114+
export function fullAncestor<TState>(
115+
node: acorn.Node,
116+
callback: FullAncestorWalkerCallback<TState>,
117+
base?: RecursiveVisitors<TState>,
118+
state?: TState
119+
): void
120+
121+
/**
122+
* builds a new walker object by using the walker functions in {@link functions} and filling in the missing ones by taking defaults from {@link base}.
123+
* @param functions
124+
* @param base
125+
*/
126+
export function make<TState>(
127+
functions: RecursiveVisitors<TState>,
128+
base?: RecursiveVisitors<TState>
129+
): RecursiveVisitors<TState>
130+
131+
/**
132+
* tries to locate a node in a tree at the given start and/or end offsets, which satisfies the predicate test. {@link start} and {@link end} can be either `null` (as wildcard) or a `number`. {@link test} may be a string (indicating a node type) or a function that takes (nodeType, node) arguments and returns a boolean indicating whether this node is interesting. {@link base} and {@link state} are optional, and can be used to specify a custom walker. Nodes are tested from inner to outer, so if two nodes match the boundaries, the inner one will be preferred.
133+
* @param node
134+
* @param start
135+
* @param end
136+
* @param type
137+
* @param base
138+
* @param state
139+
*/
140+
export function findNodeAt<TState>(
141+
node: acorn.Node,
142+
start: number | undefined,
143+
end?: number | undefined,
144+
type?: FindPredicate | string,
145+
base?: RecursiveVisitors<TState>,
146+
state?: TState
147+
): Found<TState> | undefined
148+
149+
/**
150+
* like {@link findNodeAt}, but will match any node that exists 'around' (spanning) the given position.
151+
* @param node
152+
* @param start
153+
* @param type
154+
* @param base
155+
* @param state
156+
*/
157+
export function findNodeAround<TState>(
158+
node: acorn.Node,
159+
start: number | undefined,
160+
type?: FindPredicate | string,
161+
base?: RecursiveVisitors<TState>,
162+
state?: TState
163+
): Found<TState> | undefined
164+
165+
/**
166+
* similar to {@link findNodeAround}, but will match all nodes after the given position (testing outer nodes before inner nodes).
167+
*/
168+
export const findNodeAfter: typeof findNodeAround
169+
170+
export const base: RecursiveVisitors<any>

‎deps/acorn/acorn-walk/dist/walk.d.ts

+164-108
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,170 @@
1-
import {Node} from 'acorn';
2-
3-
declare module "acorn-walk" {
4-
type FullWalkerCallback<TState> = (
5-
node: Node,
6-
state: TState,
7-
type: string
8-
) => void;
9-
10-
type FullAncestorWalkerCallback<TState> = (
11-
node: Node,
12-
state: TState | Node[],
13-
ancestors: Node[],
14-
type: string
15-
) => void;
16-
type WalkerCallback<TState> = (node: Node, state: TState) => void;
17-
18-
type SimpleWalkerFn<TState> = (
19-
node: Node,
20-
state: TState
21-
) => void;
22-
23-
type AncestorWalkerFn<TState> = (
24-
node: Node,
25-
state: TState| Node[],
26-
ancestors: Node[]
27-
) => void;
28-
29-
type RecursiveWalkerFn<TState> = (
30-
node: Node,
31-
state: TState,
32-
callback: WalkerCallback<TState>
33-
) => void;
34-
35-
type SimpleVisitors<TState> = {
36-
[type: string]: SimpleWalkerFn<TState>
37-
};
38-
39-
type AncestorVisitors<TState> = {
40-
[type: string]: AncestorWalkerFn<TState>
41-
};
42-
43-
type RecursiveVisitors<TState> = {
44-
[type: string]: RecursiveWalkerFn<TState>
45-
};
46-
47-
type FindPredicate = (type: string, node: Node) => boolean;
48-
49-
interface Found<TState> {
50-
node: Node,
51-
state: TState
52-
}
53-
54-
export function simple<TState>(
55-
node: Node,
56-
visitors: SimpleVisitors<TState>,
57-
base?: RecursiveVisitors<TState>,
58-
state?: TState
59-
): void;
1+
import * as acorn from "acorn"
2+
3+
export type FullWalkerCallback<TState> = (
4+
node: acorn.Node,
5+
state: TState,
6+
type: string
7+
) => void
8+
9+
export type FullAncestorWalkerCallback<TState> = (
10+
node: acorn.Node,
11+
state: TState,
12+
ancestors: acorn.Node[],
13+
type: string
14+
) => void
15+
16+
type AggregateType = {
17+
Expression: acorn.Expression,
18+
Statement: acorn.Statement,
19+
Pattern: acorn.Pattern,
20+
ForInit: acorn.VariableDeclaration | acorn.Expression
21+
}
6022

61-
export function ancestor<TState>(
62-
node: Node,
63-
visitors: AncestorVisitors<TState>,
64-
base?: RecursiveVisitors<TState>,
65-
state?: TState
66-
): void;
67-
68-
export function recursive<TState>(
69-
node: Node,
70-
state: TState,
71-
functions: RecursiveVisitors<TState>,
72-
base?: RecursiveVisitors<TState>
73-
): void;
74-
75-
export function full<TState>(
76-
node: Node,
77-
callback: FullWalkerCallback<TState>,
78-
base?: RecursiveVisitors<TState>,
79-
state?: TState
80-
): void;
23+
export type SimpleVisitors<TState> = {
24+
[type in acorn.AnyNode["type"]]?: (node: Extract<acorn.AnyNode, { type: type }>, state: TState) => void
25+
} & {
26+
[type in keyof AggregateType]?: (node: AggregateType[type], state: TState) => void
27+
}
8128

82-
export function fullAncestor<TState>(
83-
node: Node,
84-
callback: FullAncestorWalkerCallback<TState>,
85-
base?: RecursiveVisitors<TState>,
86-
state?: TState
87-
): void;
88-
89-
export function make<TState>(
90-
functions: RecursiveVisitors<TState>,
91-
base?: RecursiveVisitors<TState>
92-
): RecursiveVisitors<TState>;
93-
94-
export function findNodeAt<TState>(
95-
node: Node,
96-
start: number | undefined,
97-
end?: number | undefined,
98-
type?: FindPredicate | string,
99-
base?: RecursiveVisitors<TState>,
100-
state?: TState
101-
): Found<TState> | undefined;
29+
export type AncestorVisitors<TState> = {
30+
[type in acorn.AnyNode["type"]]?: ( node: Extract<acorn.AnyNode, { type: type }>, state: TState, ancestors: acorn.Node[]
31+
) => void
32+
} & {
33+
[type in keyof AggregateType]?: (node: AggregateType[type], state: TState, ancestors: acorn.Node[]) => void
34+
}
10235

103-
export function findNodeAround<TState>(
104-
node: Node,
105-
start: number | undefined,
106-
type?: FindPredicate | string,
107-
base?: RecursiveVisitors<TState>,
108-
state?: TState
109-
): Found<TState> | undefined;
36+
export type WalkerCallback<TState> = (node: acorn.Node, state: TState) => void
11037

111-
export const findNodeAfter: typeof findNodeAround;
38+
export type RecursiveVisitors<TState> = {
39+
[type in acorn.AnyNode["type"]]?: ( node: Extract<acorn.AnyNode, { type: type }>, state: TState, callback: WalkerCallback<TState>) => void
40+
} & {
41+
[type in keyof AggregateType]?: (node: AggregateType[type], state: TState, callback: WalkerCallback<TState>) => void
42+
}
11243

113-
export const base: RecursiveVisitors<any>;
44+
export type FindPredicate = (type: string, node: acorn.Node) => boolean
45+
46+
export interface Found<TState> {
47+
node: acorn.Node,
48+
state: TState
11449
}
50+
51+
/**
52+
* does a 'simple' walk over a tree
53+
* @param node the AST node to walk
54+
* @param visitors an object with properties whose names correspond to node types in the {@link https://github.com/estree/estree | ESTree spec}. The properties should contain functions that will be called with the node object and, if applicable the state at that point.
55+
* @param base a walker algorithm
56+
* @param state a start state. The default walker will simply visit all statements and expressions and not produce a meaningful state. (An example of a use of state is to track scope at each point in the tree.)
57+
*/
58+
export function simple<TState>(
59+
node: acorn.Node,
60+
visitors: SimpleVisitors<TState>,
61+
base?: RecursiveVisitors<TState>,
62+
state?: TState
63+
): void
64+
65+
/**
66+
* does a 'simple' walk over a tree, building up an array of ancestor nodes (including the current node) and passing the array to the callbacks as a third parameter.
67+
* @param node
68+
* @param visitors
69+
* @param base
70+
* @param state
71+
*/
72+
export function ancestor<TState>(
73+
node: acorn.Node,
74+
visitors: AncestorVisitors<TState>,
75+
base?: RecursiveVisitors<TState>,
76+
state?: TState
77+
): void
78+
79+
/**
80+
* does a 'recursive' walk, where the walker functions are responsible for continuing the walk on the child nodes of their target node.
81+
* @param node
82+
* @param state the start state
83+
* @param functions contain an object that maps node types to walker functions
84+
* @param base provides the fallback walker functions for node types that aren't handled in the {@link functions} object. If not given, the default walkers will be used.
85+
*/
86+
export function recursive<TState>(
87+
node: acorn.Node,
88+
state: TState,
89+
functions: RecursiveVisitors<TState>,
90+
base?: RecursiveVisitors<TState>
91+
): void
92+
93+
/**
94+
* does a 'full' walk over a tree, calling the {@link callback} with the arguments (node, state, type) for each node
95+
* @param node
96+
* @param callback
97+
* @param base
98+
* @param state
99+
*/
100+
export function full<TState>(
101+
node: acorn.Node,
102+
callback: FullWalkerCallback<TState>,
103+
base?: RecursiveVisitors<TState>,
104+
state?: TState
105+
): void
106+
107+
/**
108+
* does a 'full' walk over a tree, building up an array of ancestor nodes (including the current node) and passing the array to the callbacks as a third parameter.
109+
* @param node
110+
* @param callback
111+
* @param base
112+
* @param state
113+
*/
114+
export function fullAncestor<TState>(
115+
node: acorn.Node,
116+
callback: FullAncestorWalkerCallback<TState>,
117+
base?: RecursiveVisitors<TState>,
118+
state?: TState
119+
): void
120+
121+
/**
122+
* builds a new walker object by using the walker functions in {@link functions} and filling in the missing ones by taking defaults from {@link base}.
123+
* @param functions
124+
* @param base
125+
*/
126+
export function make<TState>(
127+
functions: RecursiveVisitors<TState>,
128+
base?: RecursiveVisitors<TState>
129+
): RecursiveVisitors<TState>
130+
131+
/**
132+
* tries to locate a node in a tree at the given start and/or end offsets, which satisfies the predicate test. {@link start} and {@link end} can be either `null` (as wildcard) or a `number`. {@link test} may be a string (indicating a node type) or a function that takes (nodeType, node) arguments and returns a boolean indicating whether this node is interesting. {@link base} and {@link state} are optional, and can be used to specify a custom walker. Nodes are tested from inner to outer, so if two nodes match the boundaries, the inner one will be preferred.
133+
* @param node
134+
* @param start
135+
* @param end
136+
* @param type
137+
* @param base
138+
* @param state
139+
*/
140+
export function findNodeAt<TState>(
141+
node: acorn.Node,
142+
start: number | undefined,
143+
end?: number | undefined,
144+
type?: FindPredicate | string,
145+
base?: RecursiveVisitors<TState>,
146+
state?: TState
147+
): Found<TState> | undefined
148+
149+
/**
150+
* like {@link findNodeAt}, but will match any node that exists 'around' (spanning) the given position.
151+
* @param node
152+
* @param start
153+
* @param type
154+
* @param base
155+
* @param state
156+
*/
157+
export function findNodeAround<TState>(
158+
node: acorn.Node,
159+
start: number | undefined,
160+
type?: FindPredicate | string,
161+
base?: RecursiveVisitors<TState>,
162+
state?: TState
163+
): Found<TState> | undefined
164+
165+
/**
166+
* similar to {@link findNodeAround}, but will match all nodes after the given position (testing outer nodes before inner nodes).
167+
*/
168+
export const findNodeAfter: typeof findNodeAround
169+
170+
export const base: RecursiveVisitors<any>

‎deps/acorn/acorn-walk/dist/walk.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
(function (global, factory) {
22
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
33
typeof define === 'function' && define.amd ? define(['exports'], factory) :
4-
(global = global || self, factory((global.acorn = global.acorn || {}, global.acorn.walk = {})));
5-
}(this, (function (exports) { 'use strict';
4+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.acorn = global.acorn || {}, global.acorn.walk = {})));
5+
})(this, (function (exports) { 'use strict';
66

77
// AST walker module for Mozilla Parser API compatible trees
88

@@ -458,6 +458,4 @@
458458
exports.recursive = recursive;
459459
exports.simple = simple;
460460

461-
Object.defineProperty(exports, '__esModule', { value: true });
462-
463-
})));
461+
}));

‎deps/acorn/acorn-walk/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
],
1717
"./package.json": "./package.json"
1818
},
19-
"version": "8.2.0",
20-
"engines": {"node": ">=0.4.0"},
19+
"version": "8.3.0",
20+
"engines": {
21+
"node": ">=0.4.0"
22+
},
2123
"maintainers": [
2224
{
2325
"name": "Marijn Haverbeke",

0 commit comments

Comments
 (0)
Please sign in to comment.