mirror of https://github.com/nodejs/node.git
deps: update acorn-walk to 8.3.0
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
7014eaca7d
commit
0281296bfe
|
@ -1,3 +1,9 @@
|
|||
## 8.3.0 (2023-10-26)
|
||||
|
||||
### New features
|
||||
|
||||
Use a set of new, much more precise, TypeScript types.
|
||||
|
||||
## 8.2.0 (2021-09-06)
|
||||
|
||||
### New features
|
||||
|
|
|
@ -10,9 +10,7 @@ Acorn is open source software released under an
|
|||
|
||||
You are welcome to
|
||||
[report bugs](https://github.com/acornjs/acorn/issues) or create pull
|
||||
requests on [github](https://github.com/acornjs/acorn). For questions
|
||||
and discussion, please use the
|
||||
[Tern discussion forum](https://discuss.ternjs.net).
|
||||
requests on [github](https://github.com/acornjs/acorn).
|
||||
|
||||
## Installation
|
||||
|
||||
|
@ -68,7 +66,7 @@ const acorn = require("acorn")
|
|||
const walk = require("acorn-walk")
|
||||
|
||||
walk.ancestor(acorn.parse("foo('hi')"), {
|
||||
Literal(_, ancestors) {
|
||||
Literal(_node, _state, ancestors) {
|
||||
console.log("This literal's ancestors are:", ancestors.map(n => n.type))
|
||||
}
|
||||
})
|
||||
|
|
|
@ -0,0 +1,170 @@
|
|||
import * as acorn from "acorn"
|
||||
|
||||
export type FullWalkerCallback<TState> = (
|
||||
node: acorn.Node,
|
||||
state: TState,
|
||||
type: string
|
||||
) => void
|
||||
|
||||
export type FullAncestorWalkerCallback<TState> = (
|
||||
node: acorn.Node,
|
||||
state: TState,
|
||||
ancestors: acorn.Node[],
|
||||
type: string
|
||||
) => void
|
||||
|
||||
type AggregateType = {
|
||||
Expression: acorn.Expression,
|
||||
Statement: acorn.Statement,
|
||||
Pattern: acorn.Pattern,
|
||||
ForInit: acorn.VariableDeclaration | acorn.Expression
|
||||
}
|
||||
|
||||
export type SimpleVisitors<TState> = {
|
||||
[type in acorn.AnyNode["type"]]?: (node: Extract<acorn.AnyNode, { type: type }>, state: TState) => void
|
||||
} & {
|
||||
[type in keyof AggregateType]?: (node: AggregateType[type], state: TState) => void
|
||||
}
|
||||
|
||||
export type AncestorVisitors<TState> = {
|
||||
[type in acorn.AnyNode["type"]]?: ( node: Extract<acorn.AnyNode, { type: type }>, state: TState, ancestors: acorn.Node[]
|
||||
) => void
|
||||
} & {
|
||||
[type in keyof AggregateType]?: (node: AggregateType[type], state: TState, ancestors: acorn.Node[]) => void
|
||||
}
|
||||
|
||||
export type WalkerCallback<TState> = (node: acorn.Node, state: TState) => void
|
||||
|
||||
export type RecursiveVisitors<TState> = {
|
||||
[type in acorn.AnyNode["type"]]?: ( node: Extract<acorn.AnyNode, { type: type }>, state: TState, callback: WalkerCallback<TState>) => void
|
||||
} & {
|
||||
[type in keyof AggregateType]?: (node: AggregateType[type], state: TState, callback: WalkerCallback<TState>) => void
|
||||
}
|
||||
|
||||
export type FindPredicate = (type: string, node: acorn.Node) => boolean
|
||||
|
||||
export interface Found<TState> {
|
||||
node: acorn.Node,
|
||||
state: TState
|
||||
}
|
||||
|
||||
/**
|
||||
* does a 'simple' walk over a tree
|
||||
* @param node the AST node to walk
|
||||
* @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.
|
||||
* @param base a walker algorithm
|
||||
* @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.)
|
||||
*/
|
||||
export function simple<TState>(
|
||||
node: acorn.Node,
|
||||
visitors: SimpleVisitors<TState>,
|
||||
base?: RecursiveVisitors<TState>,
|
||||
state?: TState
|
||||
): void
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param node
|
||||
* @param visitors
|
||||
* @param base
|
||||
* @param state
|
||||
*/
|
||||
export function ancestor<TState>(
|
||||
node: acorn.Node,
|
||||
visitors: AncestorVisitors<TState>,
|
||||
base?: RecursiveVisitors<TState>,
|
||||
state?: TState
|
||||
): void
|
||||
|
||||
/**
|
||||
* does a 'recursive' walk, where the walker functions are responsible for continuing the walk on the child nodes of their target node.
|
||||
* @param node
|
||||
* @param state the start state
|
||||
* @param functions contain an object that maps node types to walker functions
|
||||
* @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.
|
||||
*/
|
||||
export function recursive<TState>(
|
||||
node: acorn.Node,
|
||||
state: TState,
|
||||
functions: RecursiveVisitors<TState>,
|
||||
base?: RecursiveVisitors<TState>
|
||||
): void
|
||||
|
||||
/**
|
||||
* does a 'full' walk over a tree, calling the {@link callback} with the arguments (node, state, type) for each node
|
||||
* @param node
|
||||
* @param callback
|
||||
* @param base
|
||||
* @param state
|
||||
*/
|
||||
export function full<TState>(
|
||||
node: acorn.Node,
|
||||
callback: FullWalkerCallback<TState>,
|
||||
base?: RecursiveVisitors<TState>,
|
||||
state?: TState
|
||||
): void
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param node
|
||||
* @param callback
|
||||
* @param base
|
||||
* @param state
|
||||
*/
|
||||
export function fullAncestor<TState>(
|
||||
node: acorn.Node,
|
||||
callback: FullAncestorWalkerCallback<TState>,
|
||||
base?: RecursiveVisitors<TState>,
|
||||
state?: TState
|
||||
): void
|
||||
|
||||
/**
|
||||
* 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}.
|
||||
* @param functions
|
||||
* @param base
|
||||
*/
|
||||
export function make<TState>(
|
||||
functions: RecursiveVisitors<TState>,
|
||||
base?: RecursiveVisitors<TState>
|
||||
): RecursiveVisitors<TState>
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param node
|
||||
* @param start
|
||||
* @param end
|
||||
* @param type
|
||||
* @param base
|
||||
* @param state
|
||||
*/
|
||||
export function findNodeAt<TState>(
|
||||
node: acorn.Node,
|
||||
start: number | undefined,
|
||||
end?: number | undefined,
|
||||
type?: FindPredicate | string,
|
||||
base?: RecursiveVisitors<TState>,
|
||||
state?: TState
|
||||
): Found<TState> | undefined
|
||||
|
||||
/**
|
||||
* like {@link findNodeAt}, but will match any node that exists 'around' (spanning) the given position.
|
||||
* @param node
|
||||
* @param start
|
||||
* @param type
|
||||
* @param base
|
||||
* @param state
|
||||
*/
|
||||
export function findNodeAround<TState>(
|
||||
node: acorn.Node,
|
||||
start: number | undefined,
|
||||
type?: FindPredicate | string,
|
||||
base?: RecursiveVisitors<TState>,
|
||||
state?: TState
|
||||
): Found<TState> | undefined
|
||||
|
||||
/**
|
||||
* similar to {@link findNodeAround}, but will match all nodes after the given position (testing outer nodes before inner nodes).
|
||||
*/
|
||||
export const findNodeAfter: typeof findNodeAround
|
||||
|
||||
export const base: RecursiveVisitors<any>
|
|
@ -1,114 +1,170 @@
|
|||
import {Node} from 'acorn';
|
||||
import * as acorn from "acorn"
|
||||
|
||||
declare module "acorn-walk" {
|
||||
type FullWalkerCallback<TState> = (
|
||||
node: Node,
|
||||
state: TState,
|
||||
type: string
|
||||
) => void;
|
||||
export type FullWalkerCallback<TState> = (
|
||||
node: acorn.Node,
|
||||
state: TState,
|
||||
type: string
|
||||
) => void
|
||||
|
||||
type FullAncestorWalkerCallback<TState> = (
|
||||
node: Node,
|
||||
state: TState | Node[],
|
||||
ancestors: Node[],
|
||||
type: string
|
||||
) => void;
|
||||
type WalkerCallback<TState> = (node: Node, state: TState) => void;
|
||||
export type FullAncestorWalkerCallback<TState> = (
|
||||
node: acorn.Node,
|
||||
state: TState,
|
||||
ancestors: acorn.Node[],
|
||||
type: string
|
||||
) => void
|
||||
|
||||
type SimpleWalkerFn<TState> = (
|
||||
node: Node,
|
||||
state: TState
|
||||
) => void;
|
||||
|
||||
type AncestorWalkerFn<TState> = (
|
||||
node: Node,
|
||||
state: TState| Node[],
|
||||
ancestors: Node[]
|
||||
) => void;
|
||||
type AggregateType = {
|
||||
Expression: acorn.Expression,
|
||||
Statement: acorn.Statement,
|
||||
Pattern: acorn.Pattern,
|
||||
ForInit: acorn.VariableDeclaration | acorn.Expression
|
||||
}
|
||||
|
||||
type RecursiveWalkerFn<TState> = (
|
||||
node: Node,
|
||||
state: TState,
|
||||
callback: WalkerCallback<TState>
|
||||
) => void;
|
||||
|
||||
type SimpleVisitors<TState> = {
|
||||
[type: string]: SimpleWalkerFn<TState>
|
||||
};
|
||||
export type SimpleVisitors<TState> = {
|
||||
[type in acorn.AnyNode["type"]]?: (node: Extract<acorn.AnyNode, { type: type }>, state: TState) => void
|
||||
} & {
|
||||
[type in keyof AggregateType]?: (node: AggregateType[type], state: TState) => void
|
||||
}
|
||||
|
||||
type AncestorVisitors<TState> = {
|
||||
[type: string]: AncestorWalkerFn<TState>
|
||||
};
|
||||
|
||||
type RecursiveVisitors<TState> = {
|
||||
[type: string]: RecursiveWalkerFn<TState>
|
||||
};
|
||||
export type AncestorVisitors<TState> = {
|
||||
[type in acorn.AnyNode["type"]]?: ( node: Extract<acorn.AnyNode, { type: type }>, state: TState, ancestors: acorn.Node[]
|
||||
) => void
|
||||
} & {
|
||||
[type in keyof AggregateType]?: (node: AggregateType[type], state: TState, ancestors: acorn.Node[]) => void
|
||||
}
|
||||
|
||||
type FindPredicate = (type: string, node: Node) => boolean;
|
||||
export type WalkerCallback<TState> = (node: acorn.Node, state: TState) => void
|
||||
|
||||
interface Found<TState> {
|
||||
node: Node,
|
||||
state: TState
|
||||
}
|
||||
export type RecursiveVisitors<TState> = {
|
||||
[type in acorn.AnyNode["type"]]?: ( node: Extract<acorn.AnyNode, { type: type }>, state: TState, callback: WalkerCallback<TState>) => void
|
||||
} & {
|
||||
[type in keyof AggregateType]?: (node: AggregateType[type], state: TState, callback: WalkerCallback<TState>) => void
|
||||
}
|
||||
|
||||
export function simple<TState>(
|
||||
node: Node,
|
||||
visitors: SimpleVisitors<TState>,
|
||||
base?: RecursiveVisitors<TState>,
|
||||
state?: TState
|
||||
): void;
|
||||
export type FindPredicate = (type: string, node: acorn.Node) => boolean
|
||||
|
||||
export function ancestor<TState>(
|
||||
node: Node,
|
||||
export interface Found<TState> {
|
||||
node: acorn.Node,
|
||||
state: TState
|
||||
}
|
||||
|
||||
/**
|
||||
* does a 'simple' walk over a tree
|
||||
* @param node the AST node to walk
|
||||
* @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.
|
||||
* @param base a walker algorithm
|
||||
* @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.)
|
||||
*/
|
||||
export function simple<TState>(
|
||||
node: acorn.Node,
|
||||
visitors: SimpleVisitors<TState>,
|
||||
base?: RecursiveVisitors<TState>,
|
||||
state?: TState
|
||||
): void
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param node
|
||||
* @param visitors
|
||||
* @param base
|
||||
* @param state
|
||||
*/
|
||||
export function ancestor<TState>(
|
||||
node: acorn.Node,
|
||||
visitors: AncestorVisitors<TState>,
|
||||
base?: RecursiveVisitors<TState>,
|
||||
state?: TState
|
||||
): void;
|
||||
): void
|
||||
|
||||
export function recursive<TState>(
|
||||
node: Node,
|
||||
state: TState,
|
||||
functions: RecursiveVisitors<TState>,
|
||||
base?: RecursiveVisitors<TState>
|
||||
): void;
|
||||
/**
|
||||
* does a 'recursive' walk, where the walker functions are responsible for continuing the walk on the child nodes of their target node.
|
||||
* @param node
|
||||
* @param state the start state
|
||||
* @param functions contain an object that maps node types to walker functions
|
||||
* @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.
|
||||
*/
|
||||
export function recursive<TState>(
|
||||
node: acorn.Node,
|
||||
state: TState,
|
||||
functions: RecursiveVisitors<TState>,
|
||||
base?: RecursiveVisitors<TState>
|
||||
): void
|
||||
|
||||
export function full<TState>(
|
||||
node: Node,
|
||||
callback: FullWalkerCallback<TState>,
|
||||
base?: RecursiveVisitors<TState>,
|
||||
state?: TState
|
||||
): void;
|
||||
/**
|
||||
* does a 'full' walk over a tree, calling the {@link callback} with the arguments (node, state, type) for each node
|
||||
* @param node
|
||||
* @param callback
|
||||
* @param base
|
||||
* @param state
|
||||
*/
|
||||
export function full<TState>(
|
||||
node: acorn.Node,
|
||||
callback: FullWalkerCallback<TState>,
|
||||
base?: RecursiveVisitors<TState>,
|
||||
state?: TState
|
||||
): void
|
||||
|
||||
export function fullAncestor<TState>(
|
||||
node: Node,
|
||||
callback: FullAncestorWalkerCallback<TState>,
|
||||
base?: RecursiveVisitors<TState>,
|
||||
state?: TState
|
||||
): void;
|
||||
/**
|
||||
* 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.
|
||||
* @param node
|
||||
* @param callback
|
||||
* @param base
|
||||
* @param state
|
||||
*/
|
||||
export function fullAncestor<TState>(
|
||||
node: acorn.Node,
|
||||
callback: FullAncestorWalkerCallback<TState>,
|
||||
base?: RecursiveVisitors<TState>,
|
||||
state?: TState
|
||||
): void
|
||||
|
||||
export function make<TState>(
|
||||
functions: RecursiveVisitors<TState>,
|
||||
base?: RecursiveVisitors<TState>
|
||||
): RecursiveVisitors<TState>;
|
||||
/**
|
||||
* 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}.
|
||||
* @param functions
|
||||
* @param base
|
||||
*/
|
||||
export function make<TState>(
|
||||
functions: RecursiveVisitors<TState>,
|
||||
base?: RecursiveVisitors<TState>
|
||||
): RecursiveVisitors<TState>
|
||||
|
||||
export function findNodeAt<TState>(
|
||||
node: Node,
|
||||
start: number | undefined,
|
||||
end?: number | undefined,
|
||||
type?: FindPredicate | string,
|
||||
base?: RecursiveVisitors<TState>,
|
||||
state?: TState
|
||||
): Found<TState> | undefined;
|
||||
/**
|
||||
* 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.
|
||||
* @param node
|
||||
* @param start
|
||||
* @param end
|
||||
* @param type
|
||||
* @param base
|
||||
* @param state
|
||||
*/
|
||||
export function findNodeAt<TState>(
|
||||
node: acorn.Node,
|
||||
start: number | undefined,
|
||||
end?: number | undefined,
|
||||
type?: FindPredicate | string,
|
||||
base?: RecursiveVisitors<TState>,
|
||||
state?: TState
|
||||
): Found<TState> | undefined
|
||||
|
||||
export function findNodeAround<TState>(
|
||||
node: Node,
|
||||
start: number | undefined,
|
||||
type?: FindPredicate | string,
|
||||
base?: RecursiveVisitors<TState>,
|
||||
state?: TState
|
||||
): Found<TState> | undefined;
|
||||
/**
|
||||
* like {@link findNodeAt}, but will match any node that exists 'around' (spanning) the given position.
|
||||
* @param node
|
||||
* @param start
|
||||
* @param type
|
||||
* @param base
|
||||
* @param state
|
||||
*/
|
||||
export function findNodeAround<TState>(
|
||||
node: acorn.Node,
|
||||
start: number | undefined,
|
||||
type?: FindPredicate | string,
|
||||
base?: RecursiveVisitors<TState>,
|
||||
state?: TState
|
||||
): Found<TState> | undefined
|
||||
|
||||
export const findNodeAfter: typeof findNodeAround;
|
||||
/**
|
||||
* similar to {@link findNodeAround}, but will match all nodes after the given position (testing outer nodes before inner nodes).
|
||||
*/
|
||||
export const findNodeAfter: typeof findNodeAround
|
||||
|
||||
export const base: RecursiveVisitors<any>;
|
||||
}
|
||||
export const base: RecursiveVisitors<any>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
||||
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
||||
(global = global || self, factory((global.acorn = global.acorn || {}, global.acorn.walk = {})));
|
||||
}(this, (function (exports) { 'use strict';
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.acorn = global.acorn || {}, global.acorn.walk = {})));
|
||||
})(this, (function (exports) { 'use strict';
|
||||
|
||||
// AST walker module for Mozilla Parser API compatible trees
|
||||
|
||||
|
@ -458,6 +458,4 @@
|
|||
exports.recursive = recursive;
|
||||
exports.simple = simple;
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
})));
|
||||
}));
|
||||
|
|
|
@ -16,8 +16,10 @@
|
|||
],
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"version": "8.2.0",
|
||||
"engines": {"node": ">=0.4.0"},
|
||||
"version": "8.3.0",
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
},
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "Marijn Haverbeke",
|
||||
|
|
Loading…
Reference in New Issue