diff --git a/deps/acorn/acorn-walk/CHANGELOG.md b/deps/acorn/acorn-walk/CHANGELOG.md index 30ec5a5eec9911..0b4eea8a95d3ed 100644 --- a/deps/acorn/acorn-walk/CHANGELOG.md +++ b/deps/acorn/acorn-walk/CHANGELOG.md @@ -1,3 +1,17 @@ +## 8.3.1 (2023-12-06) + +### Bug fixes + +Add `Function` and `Class` to the `AggregateType` type, so that they can be used in walkers without raising a type error. + +Visitor functions are now called in such a way that their `this` refers to the object they are part of. + +## 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 diff --git a/deps/acorn/acorn-walk/README.md b/deps/acorn/acorn-walk/README.md index e192baced005ac..3c18a2c76a938e 100644 --- a/deps/acorn/acorn-walk/README.md +++ b/deps/acorn/acorn-walk/README.md @@ -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)) } }) diff --git a/deps/acorn/acorn-walk/dist/walk.d.mts b/deps/acorn/acorn-walk/dist/walk.d.mts new file mode 100644 index 00000000000000..7bc8c9790fd1a7 --- /dev/null +++ b/deps/acorn/acorn-walk/dist/walk.d.mts @@ -0,0 +1,172 @@ +import * as acorn from "acorn" + +export type FullWalkerCallback = ( + node: acorn.Node, + state: TState, + type: string +) => void + +export type FullAncestorWalkerCallback = ( + node: acorn.Node, + state: TState, + ancestors: acorn.Node[], + type: string +) => void + +type AggregateType = { + Expression: acorn.Expression, + Statement: acorn.Statement, + Function: acorn.Function, + Class: acorn.Class, + Pattern: acorn.Pattern, + ForInit: acorn.VariableDeclaration | acorn.Expression +} + +export type SimpleVisitors = { + [type in acorn.AnyNode["type"]]?: (node: Extract, state: TState) => void +} & { + [type in keyof AggregateType]?: (node: AggregateType[type], state: TState) => void +} + +export type AncestorVisitors = { + [type in acorn.AnyNode["type"]]?: ( node: Extract, state: TState, ancestors: acorn.Node[] +) => void +} & { + [type in keyof AggregateType]?: (node: AggregateType[type], state: TState, ancestors: acorn.Node[]) => void +} + +export type WalkerCallback = (node: acorn.Node, state: TState) => void + +export type RecursiveVisitors = { + [type in acorn.AnyNode["type"]]?: ( node: Extract, state: TState, callback: WalkerCallback) => void +} & { + [type in keyof AggregateType]?: (node: AggregateType[type], state: TState, callback: WalkerCallback) => void +} + +export type FindPredicate = (type: string, node: acorn.Node) => boolean + +export interface Found { + 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( + node: acorn.Node, + visitors: SimpleVisitors, + base?: RecursiveVisitors, + 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( + node: acorn.Node, + visitors: AncestorVisitors, + base?: RecursiveVisitors, + 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( + node: acorn.Node, + state: TState, + functions: RecursiveVisitors, + base?: RecursiveVisitors +): 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( + node: acorn.Node, + callback: FullWalkerCallback, + base?: RecursiveVisitors, + 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( + node: acorn.Node, + callback: FullAncestorWalkerCallback, + base?: RecursiveVisitors, + 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( + functions: RecursiveVisitors, + base?: RecursiveVisitors +): RecursiveVisitors + +/** + * 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( + node: acorn.Node, + start: number | undefined, + end?: number | undefined, + type?: FindPredicate | string, + base?: RecursiveVisitors, + state?: TState +): Found | 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( + node: acorn.Node, + start: number | undefined, + type?: FindPredicate | string, + base?: RecursiveVisitors, + state?: TState +): Found | 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 diff --git a/deps/acorn/acorn-walk/dist/walk.d.ts b/deps/acorn/acorn-walk/dist/walk.d.ts index 2d81f01c166875..7bc8c9790fd1a7 100644 --- a/deps/acorn/acorn-walk/dist/walk.d.ts +++ b/deps/acorn/acorn-walk/dist/walk.d.ts @@ -1,114 +1,172 @@ -import {Node} from 'acorn'; - -declare module "acorn-walk" { - type FullWalkerCallback = ( - node: Node, - state: TState, - type: string - ) => void; - - type FullAncestorWalkerCallback = ( - node: Node, - state: TState | Node[], - ancestors: Node[], - type: string - ) => void; - type WalkerCallback = (node: Node, state: TState) => void; - - type SimpleWalkerFn = ( - node: Node, - state: TState - ) => void; - - type AncestorWalkerFn = ( - node: Node, - state: TState| Node[], - ancestors: Node[] - ) => void; - - type RecursiveWalkerFn = ( - node: Node, - state: TState, - callback: WalkerCallback - ) => void; - - type SimpleVisitors = { - [type: string]: SimpleWalkerFn - }; - - type AncestorVisitors = { - [type: string]: AncestorWalkerFn - }; - - type RecursiveVisitors = { - [type: string]: RecursiveWalkerFn - }; - - type FindPredicate = (type: string, node: Node) => boolean; - - interface Found { - node: Node, - state: TState - } - - export function simple( - node: Node, - visitors: SimpleVisitors, - base?: RecursiveVisitors, - state?: TState - ): void; +import * as acorn from "acorn" + +export type FullWalkerCallback = ( + node: acorn.Node, + state: TState, + type: string +) => void + +export type FullAncestorWalkerCallback = ( + node: acorn.Node, + state: TState, + ancestors: acorn.Node[], + type: string +) => void + +type AggregateType = { + Expression: acorn.Expression, + Statement: acorn.Statement, + Function: acorn.Function, + Class: acorn.Class, + Pattern: acorn.Pattern, + ForInit: acorn.VariableDeclaration | acorn.Expression +} - export function ancestor( - node: Node, - visitors: AncestorVisitors, - base?: RecursiveVisitors, - state?: TState - ): void; - - export function recursive( - node: Node, - state: TState, - functions: RecursiveVisitors, - base?: RecursiveVisitors - ): void; - - export function full( - node: Node, - callback: FullWalkerCallback, - base?: RecursiveVisitors, - state?: TState - ): void; +export type SimpleVisitors = { + [type in acorn.AnyNode["type"]]?: (node: Extract, state: TState) => void +} & { + [type in keyof AggregateType]?: (node: AggregateType[type], state: TState) => void +} - export function fullAncestor( - node: Node, - callback: FullAncestorWalkerCallback, - base?: RecursiveVisitors, - state?: TState - ): void; - - export function make( - functions: RecursiveVisitors, - base?: RecursiveVisitors - ): RecursiveVisitors; - - export function findNodeAt( - node: Node, - start: number | undefined, - end?: number | undefined, - type?: FindPredicate | string, - base?: RecursiveVisitors, - state?: TState - ): Found | undefined; +export type AncestorVisitors = { + [type in acorn.AnyNode["type"]]?: ( node: Extract, state: TState, ancestors: acorn.Node[] +) => void +} & { + [type in keyof AggregateType]?: (node: AggregateType[type], state: TState, ancestors: acorn.Node[]) => void +} - export function findNodeAround( - node: Node, - start: number | undefined, - type?: FindPredicate | string, - base?: RecursiveVisitors, - state?: TState - ): Found | undefined; +export type WalkerCallback = (node: acorn.Node, state: TState) => void - export const findNodeAfter: typeof findNodeAround; +export type RecursiveVisitors = { + [type in acorn.AnyNode["type"]]?: ( node: Extract, state: TState, callback: WalkerCallback) => void +} & { + [type in keyof AggregateType]?: (node: AggregateType[type], state: TState, callback: WalkerCallback) => void +} - export const base: RecursiveVisitors; +export type FindPredicate = (type: string, node: acorn.Node) => boolean + +export interface Found { + 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( + node: acorn.Node, + visitors: SimpleVisitors, + base?: RecursiveVisitors, + 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( + node: acorn.Node, + visitors: AncestorVisitors, + base?: RecursiveVisitors, + 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( + node: acorn.Node, + state: TState, + functions: RecursiveVisitors, + base?: RecursiveVisitors +): 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( + node: acorn.Node, + callback: FullWalkerCallback, + base?: RecursiveVisitors, + 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( + node: acorn.Node, + callback: FullAncestorWalkerCallback, + base?: RecursiveVisitors, + 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( + functions: RecursiveVisitors, + base?: RecursiveVisitors +): RecursiveVisitors + +/** + * 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( + node: acorn.Node, + start: number | undefined, + end?: number | undefined, + type?: FindPredicate | string, + base?: RecursiveVisitors, + state?: TState +): Found | 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( + node: acorn.Node, + start: number | undefined, + type?: FindPredicate | string, + base?: RecursiveVisitors, + state?: TState +): Found | 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 diff --git a/deps/acorn/acorn-walk/dist/walk.js b/deps/acorn/acorn-walk/dist/walk.js index a7f81b0061a750..580df6413725f8 100644 --- a/deps/acorn/acorn-walk/dist/walk.js +++ b/deps/acorn/acorn-walk/dist/walk.js @@ -1,10 +1,10 @@ (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 + // AST walker module for ESTree compatible trees // A simple walk is one where you simply specify callbacks to be // called on specific nodes. The last two arguments are optional. A @@ -14,7 +14,7 @@ // Expression: function(node) { ... } // }); // - // to do something with all expressions. All Parser API node types + // to do something with all expressions. All ESTree node types // can be used to identify node types, as well as Expression and // Statement, which denote categories of nodes. // @@ -25,9 +25,9 @@ function simple(node, visitors, baseVisitor, state, override) { if (!baseVisitor) { baseVisitor = base ; }(function c(node, st, override) { - var type = override || node.type, found = visitors[type]; + var type = override || node.type; baseVisitor[type](node, st, c); - if (found) { found(node, st); } + if (visitors[type]) { visitors[type](node, st); } })(node, state, override); } @@ -38,11 +38,11 @@ var ancestors = []; if (!baseVisitor) { baseVisitor = base ; }(function c(node, st, override) { - var type = override || node.type, found = visitors[type]; + var type = override || node.type; var isNew = node !== ancestors[ancestors.length - 1]; if (isNew) { ancestors.push(node); } baseVisitor[type](node, st, c); - if (found) { found(node, st || ancestors, ancestors); } + if (visitors[type]) { visitors[type](node, st || ancestors, ancestors); } if (isNew) { ancestors.pop(); } })(node, state, override); } @@ -458,6 +458,4 @@ exports.recursive = recursive; exports.simple = simple; - Object.defineProperty(exports, '__esModule', { value: true }); - -}))); +})); diff --git a/deps/acorn/acorn-walk/dist/walk.mjs b/deps/acorn/acorn-walk/dist/walk.mjs index 89dd1f1f4f3557..19eebc0e70f598 100644 --- a/deps/acorn/acorn-walk/dist/walk.mjs +++ b/deps/acorn/acorn-walk/dist/walk.mjs @@ -1,4 +1,4 @@ -// AST walker module for Mozilla Parser API compatible trees +// AST walker module for ESTree compatible trees // A simple walk is one where you simply specify callbacks to be // called on specific nodes. The last two arguments are optional. A @@ -8,7 +8,7 @@ // Expression: function(node) { ... } // }); // -// to do something with all expressions. All Parser API node types +// to do something with all expressions. All ESTree node types // can be used to identify node types, as well as Expression and // Statement, which denote categories of nodes. // @@ -19,9 +19,9 @@ function simple(node, visitors, baseVisitor, state, override) { if (!baseVisitor) { baseVisitor = base ; }(function c(node, st, override) { - var type = override || node.type, found = visitors[type]; + var type = override || node.type; baseVisitor[type](node, st, c); - if (found) { found(node, st); } + if (visitors[type]) { visitors[type](node, st); } })(node, state, override); } @@ -32,11 +32,11 @@ function ancestor(node, visitors, baseVisitor, state, override) { var ancestors = []; if (!baseVisitor) { baseVisitor = base ; }(function c(node, st, override) { - var type = override || node.type, found = visitors[type]; + var type = override || node.type; var isNew = node !== ancestors[ancestors.length - 1]; if (isNew) { ancestors.push(node); } baseVisitor[type](node, st, c); - if (found) { found(node, st || ancestors, ancestors); } + if (visitors[type]) { visitors[type](node, st || ancestors, ancestors); } if (isNew) { ancestors.pop(); } })(node, state, override); } diff --git a/deps/acorn/acorn-walk/package.json b/deps/acorn/acorn-walk/package.json index 8d75b9711c2e35..393c87a39255a0 100644 --- a/deps/acorn/acorn-walk/package.json +++ b/deps/acorn/acorn-walk/package.json @@ -16,8 +16,10 @@ ], "./package.json": "./package.json" }, - "version": "8.2.0", - "engines": {"node": ">=0.4.0"}, + "version": "8.3.1", + "engines": { + "node": ">=0.4.0" + }, "maintainers": [ { "name": "Marijn Haverbeke",