diff --git a/deps/acorn/acorn-walk/CHANGELOG.md b/deps/acorn/acorn-walk/CHANGELOG.md index 7aeae8fd5c8622..de4168f21a4508 100644 --- a/deps/acorn/acorn-walk/CHANGELOG.md +++ b/deps/acorn/acorn-walk/CHANGELOG.md @@ -1,3 +1,13 @@ +## 8.3.5 (2026-02-19) + +### Bug fixes + +Emit a more informative error message when trying to walk a node type that has no walker function. + +Specify callbacks in types to receive `AnyNode` type, so that they can be narrowed more easily. + +Support import attributes. + ## 8.3.4 (2024-09-09) ### Bug fixes diff --git a/deps/acorn/acorn-walk/README.md b/deps/acorn/acorn-walk/README.md index 3c18a2c76a938e..eaec57fda3b3ff 100644 --- a/deps/acorn/acorn-walk/README.md +++ b/deps/acorn/acorn-walk/README.md @@ -47,8 +47,8 @@ produce a meaningful state. (An example of a use of state is to track scope at each point in the tree.) ```js -const acorn = require("acorn") -const walk = require("acorn-walk") +import * as acorn from "acorn" +import * as walk from "acorn-walk" walk.simple(acorn.parse("let x = 10"), { Literal(node) { @@ -62,8 +62,8 @@ a tree, building up an array of ancestor nodes (including the current node) and passing the array to the callbacks as a third parameter. ```js -const acorn = require("acorn") -const walk = require("acorn-walk") +import * as acorn from "acorn" +import * as walk from "acorn-walk" walk.ancestor(acorn.parse("foo('hi')"), { Literal(_node, _state, ancestors) { @@ -97,8 +97,8 @@ current node) and passing the array to the callbacks as a third parameter. ```js -const acorn = require("acorn") -const walk = require("acorn-walk") +import * as acorn from "acorn" +import * as walk from "acorn-walk" walk.full(acorn.parse("1 + 1"), node => { console.log(`There's a ${node.type} node at ${node.ch}`) diff --git a/deps/acorn/acorn-walk/dist/walk.d.mts b/deps/acorn/acorn-walk/dist/walk.d.mts index e07a6afaf8e336..199c8a0159b8f2 100644 --- a/deps/acorn/acorn-walk/dist/walk.d.mts +++ b/deps/acorn/acorn-walk/dist/walk.d.mts @@ -1,15 +1,15 @@ import * as acorn from "acorn" export type FullWalkerCallback = ( - node: acorn.Node, + node: acorn.AnyNode, state: TState, type: string ) => void export type FullAncestorWalkerCallback = ( - node: acorn.Node, + node: acorn.AnyNode, state: TState, - ancestors: acorn.Node[], + ancestors: acorn.AnyNode[], type: string ) => void @@ -29,13 +29,13 @@ export type SimpleVisitors = { } export type AncestorVisitors = { - [type in acorn.AnyNode["type"]]?: ( node: Extract, state: TState, ancestors: acorn.Node[] + [type in acorn.AnyNode["type"]]?: ( node: Extract, state: TState, ancestors: acorn.AnyNode[] ) => void } & { - [type in keyof AggregateType]?: (node: AggregateType[type], state: TState, ancestors: acorn.Node[]) => void + [type in keyof AggregateType]?: (node: AggregateType[type], state: TState, ancestors: acorn.AnyNode[]) => void } -export type WalkerCallback = (node: acorn.Node, state: TState) => void +export type WalkerCallback = (node: acorn.AnyNode, state: TState) => void export type RecursiveVisitors = { [type in acorn.AnyNode["type"]]?: ( node: Extract, state: TState, callback: WalkerCallback) => void @@ -43,10 +43,10 @@ export type RecursiveVisitors = { [type in keyof AggregateType]?: (node: AggregateType[type], state: TState, callback: WalkerCallback) => void } -export type FindPredicate = (type: string, node: acorn.Node) => boolean +export type FindPredicate = (type: string, node: acorn.AnyNode) => boolean export interface Found { - node: acorn.Node, + node: acorn.AnyNode, state: TState } @@ -66,10 +66,6 @@ export function simple( /** * 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, @@ -94,10 +90,6 @@ export function recursive( /** * 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, @@ -108,10 +100,6 @@ export function full( /** * 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, @@ -122,8 +110,6 @@ export function fullAncestor( /** * 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, @@ -132,17 +118,11 @@ export function make( /** * 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, + start: number | undefined | null, + end?: number | undefined | null, type?: FindPredicate | string, base?: RecursiveVisitors, state?: TState @@ -150,15 +130,10 @@ export function findNodeAt( /** * 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, + start: number | undefined | null, type?: FindPredicate | string, base?: RecursiveVisitors, state?: TState diff --git a/deps/acorn/acorn-walk/dist/walk.d.ts b/deps/acorn/acorn-walk/dist/walk.d.ts index e07a6afaf8e336..199c8a0159b8f2 100644 --- a/deps/acorn/acorn-walk/dist/walk.d.ts +++ b/deps/acorn/acorn-walk/dist/walk.d.ts @@ -1,15 +1,15 @@ import * as acorn from "acorn" export type FullWalkerCallback = ( - node: acorn.Node, + node: acorn.AnyNode, state: TState, type: string ) => void export type FullAncestorWalkerCallback = ( - node: acorn.Node, + node: acorn.AnyNode, state: TState, - ancestors: acorn.Node[], + ancestors: acorn.AnyNode[], type: string ) => void @@ -29,13 +29,13 @@ export type SimpleVisitors = { } export type AncestorVisitors = { - [type in acorn.AnyNode["type"]]?: ( node: Extract, state: TState, ancestors: acorn.Node[] + [type in acorn.AnyNode["type"]]?: ( node: Extract, state: TState, ancestors: acorn.AnyNode[] ) => void } & { - [type in keyof AggregateType]?: (node: AggregateType[type], state: TState, ancestors: acorn.Node[]) => void + [type in keyof AggregateType]?: (node: AggregateType[type], state: TState, ancestors: acorn.AnyNode[]) => void } -export type WalkerCallback = (node: acorn.Node, state: TState) => void +export type WalkerCallback = (node: acorn.AnyNode, state: TState) => void export type RecursiveVisitors = { [type in acorn.AnyNode["type"]]?: ( node: Extract, state: TState, callback: WalkerCallback) => void @@ -43,10 +43,10 @@ export type RecursiveVisitors = { [type in keyof AggregateType]?: (node: AggregateType[type], state: TState, callback: WalkerCallback) => void } -export type FindPredicate = (type: string, node: acorn.Node) => boolean +export type FindPredicate = (type: string, node: acorn.AnyNode) => boolean export interface Found { - node: acorn.Node, + node: acorn.AnyNode, state: TState } @@ -66,10 +66,6 @@ export function simple( /** * 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, @@ -94,10 +90,6 @@ export function recursive( /** * 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, @@ -108,10 +100,6 @@ export function full( /** * 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, @@ -122,8 +110,6 @@ export function fullAncestor( /** * 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, @@ -132,17 +118,11 @@ export function make( /** * 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, + start: number | undefined | null, + end?: number | undefined | null, type?: FindPredicate | string, base?: RecursiveVisitors, state?: TState @@ -150,15 +130,10 @@ export function findNodeAt( /** * 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, + start: number | undefined | null, type?: FindPredicate | string, base?: RecursiveVisitors, state?: TState diff --git a/deps/acorn/acorn-walk/dist/walk.js b/deps/acorn/acorn-walk/dist/walk.js index 40b7aa1b078a18..fe4d19759b7da3 100644 --- a/deps/acorn/acorn-walk/dist/walk.js +++ b/deps/acorn/acorn-walk/dist/walk.js @@ -26,7 +26,7 @@ if (!baseVisitor) { baseVisitor = base ; }(function c(node, st, override) { var type = override || node.type; - baseVisitor[type](node, st, c); + visitNode(baseVisitor, type, node, st, c); if (visitors[type]) { visitors[type](node, st); } })(node, state, override); } @@ -41,7 +41,7 @@ var type = override || node.type; var isNew = node !== ancestors[ancestors.length - 1]; if (isNew) { ancestors.push(node); } - baseVisitor[type](node, st, c); + visitNode(baseVisitor, type, node, st, c); if (visitors[type]) { visitors[type](node, st || ancestors, ancestors); } if (isNew) { ancestors.pop(); } })(node, state, override); @@ -76,7 +76,7 @@ var last ;(function c(node, st, override) { var type = override || node.type; - baseVisitor[type](node, st, c); + visitNode(baseVisitor, type, node, st, c); if (last !== node) { callback(node, st, type); last = node; @@ -93,7 +93,7 @@ var type = override || node.type; var isNew = node !== ancestors[ancestors.length - 1]; if (isNew) { ancestors.push(node); } - baseVisitor[type](node, st, c); + visitNode(baseVisitor, type, node, st, c); if (last !== node) { callback(node, st || ancestors, ancestors, type); last = node; @@ -113,7 +113,7 @@ var type = override || node.type; if ((start == null || node.start <= start) && (end == null || node.end >= end)) - { baseVisitor[type](node, st, c); } + { visitNode(baseVisitor, type, node, st, c); } if ((start == null || node.start === start) && (end == null || node.end === end) && test(type, node)) @@ -134,7 +134,7 @@ (function c(node, st, override) { var type = override || node.type; if (node.start > pos || node.end < pos) { return } - baseVisitor[type](node, st, c); + visitNode(baseVisitor, type, node, st, c); if (test(type, node)) { throw new Found(node, st) } })(node, state); } catch (e) { @@ -152,7 +152,7 @@ if (node.end < pos) { return } var type = override || node.type; if (node.start >= pos && test(type, node)) { throw new Found(node, st) } - baseVisitor[type](node, st, c); + visitNode(baseVisitor, type, node, st, c); })(node, state); } catch (e) { if (e instanceof Found) { return e } @@ -170,7 +170,7 @@ var type = override || node.type; if (node.end <= pos && (!max || max.node.end < node.end) && test(type, node)) { max = new Found(node, st); } - baseVisitor[type](node, st, c); + visitNode(baseVisitor, type, node, st, c); })(node, state); return max } @@ -186,6 +186,11 @@ function skipThrough(node, st, c) { c(node, st); } function ignore(_node, _st, _c) {} + function visitNode(baseVisitor, type, node, st, c) { + if (baseVisitor[type] == null) { throw new Error(("No walker function defined for node type " + type)) } + baseVisitor[type](node, st, c); + } + // Node walkers. var base = {}; @@ -397,11 +402,28 @@ if (node.declaration) { c(node.declaration, st, node.type === "ExportNamedDeclaration" || node.declaration.id ? "Statement" : "Expression"); } if (node.source) { c(node.source, st, "Expression"); } + if (node.attributes) + { for (var i = 0, list = node.attributes; i < list.length; i += 1) + { + var attr = list[i]; + + c(attr, st); + } } }; base.ExportAllDeclaration = function (node, st, c) { if (node.exported) { c(node.exported, st); } c(node.source, st, "Expression"); + if (node.attributes) + { for (var i = 0, list = node.attributes; i < list.length; i += 1) + { + var attr = list[i]; + + c(attr, st); + } } + }; + base.ImportAttribute = function (node, st, c) { + c(node.value, st, "Expression"); }; base.ImportDeclaration = function (node, st, c) { for (var i = 0, list = node.specifiers; i < list.length; i += 1) @@ -411,9 +433,17 @@ c(spec, st); } c(node.source, st, "Expression"); + if (node.attributes) + { for (var i$1 = 0, list$1 = node.attributes; i$1 < list$1.length; i$1 += 1) + { + var attr = list$1[i$1]; + + c(attr, st); + } } }; base.ImportExpression = function (node, st, c) { c(node.source, st, "Expression"); + if (node.options) { c(node.options, st, "Expression"); } }; base.ImportSpecifier = base.ImportDefaultSpecifier = base.ImportNamespaceSpecifier = base.Identifier = base.PrivateIdentifier = base.Literal = ignore; diff --git a/deps/acorn/acorn-walk/dist/walk.mjs b/deps/acorn/acorn-walk/dist/walk.mjs index c475ababc7ac30..88f18bb616e1d9 100644 --- a/deps/acorn/acorn-walk/dist/walk.mjs +++ b/deps/acorn/acorn-walk/dist/walk.mjs @@ -20,7 +20,7 @@ function simple(node, visitors, baseVisitor, state, override) { if (!baseVisitor) { baseVisitor = base ; }(function c(node, st, override) { var type = override || node.type; - baseVisitor[type](node, st, c); + visitNode(baseVisitor, type, node, st, c); if (visitors[type]) { visitors[type](node, st); } })(node, state, override); } @@ -35,7 +35,7 @@ function ancestor(node, visitors, baseVisitor, state, override) { var type = override || node.type; var isNew = node !== ancestors[ancestors.length - 1]; if (isNew) { ancestors.push(node); } - baseVisitor[type](node, st, c); + visitNode(baseVisitor, type, node, st, c); if (visitors[type]) { visitors[type](node, st || ancestors, ancestors); } if (isNew) { ancestors.pop(); } })(node, state, override); @@ -70,7 +70,7 @@ function full(node, callback, baseVisitor, state, override) { var last ;(function c(node, st, override) { var type = override || node.type; - baseVisitor[type](node, st, c); + visitNode(baseVisitor, type, node, st, c); if (last !== node) { callback(node, st, type); last = node; @@ -87,7 +87,7 @@ function fullAncestor(node, callback, baseVisitor, state) { var type = override || node.type; var isNew = node !== ancestors[ancestors.length - 1]; if (isNew) { ancestors.push(node); } - baseVisitor[type](node, st, c); + visitNode(baseVisitor, type, node, st, c); if (last !== node) { callback(node, st || ancestors, ancestors, type); last = node; @@ -107,7 +107,7 @@ function findNodeAt(node, start, end, test, baseVisitor, state) { var type = override || node.type; if ((start == null || node.start <= start) && (end == null || node.end >= end)) - { baseVisitor[type](node, st, c); } + { visitNode(baseVisitor, type, node, st, c); } if ((start == null || node.start === start) && (end == null || node.end === end) && test(type, node)) @@ -128,7 +128,7 @@ function findNodeAround(node, pos, test, baseVisitor, state) { (function c(node, st, override) { var type = override || node.type; if (node.start > pos || node.end < pos) { return } - baseVisitor[type](node, st, c); + visitNode(baseVisitor, type, node, st, c); if (test(type, node)) { throw new Found(node, st) } })(node, state); } catch (e) { @@ -146,7 +146,7 @@ function findNodeAfter(node, pos, test, baseVisitor, state) { if (node.end < pos) { return } var type = override || node.type; if (node.start >= pos && test(type, node)) { throw new Found(node, st) } - baseVisitor[type](node, st, c); + visitNode(baseVisitor, type, node, st, c); })(node, state); } catch (e) { if (e instanceof Found) { return e } @@ -164,7 +164,7 @@ function findNodeBefore(node, pos, test, baseVisitor, state) { var type = override || node.type; if (node.end <= pos && (!max || max.node.end < node.end) && test(type, node)) { max = new Found(node, st); } - baseVisitor[type](node, st, c); + visitNode(baseVisitor, type, node, st, c); })(node, state); return max } @@ -180,6 +180,11 @@ function make(funcs, baseVisitor) { function skipThrough(node, st, c) { c(node, st); } function ignore(_node, _st, _c) {} +function visitNode(baseVisitor, type, node, st, c) { + if (baseVisitor[type] == null) { throw new Error(("No walker function defined for node type " + type)) } + baseVisitor[type](node, st, c); +} + // Node walkers. var base = {}; @@ -391,11 +396,28 @@ base.ExportNamedDeclaration = base.ExportDefaultDeclaration = function (node, st if (node.declaration) { c(node.declaration, st, node.type === "ExportNamedDeclaration" || node.declaration.id ? "Statement" : "Expression"); } if (node.source) { c(node.source, st, "Expression"); } + if (node.attributes) + { for (var i = 0, list = node.attributes; i < list.length; i += 1) + { + var attr = list[i]; + + c(attr, st); + } } }; base.ExportAllDeclaration = function (node, st, c) { if (node.exported) { c(node.exported, st); } c(node.source, st, "Expression"); + if (node.attributes) + { for (var i = 0, list = node.attributes; i < list.length; i += 1) + { + var attr = list[i]; + + c(attr, st); + } } +}; +base.ImportAttribute = function (node, st, c) { + c(node.value, st, "Expression"); }; base.ImportDeclaration = function (node, st, c) { for (var i = 0, list = node.specifiers; i < list.length; i += 1) @@ -405,9 +427,17 @@ base.ImportDeclaration = function (node, st, c) { c(spec, st); } c(node.source, st, "Expression"); + if (node.attributes) + { for (var i$1 = 0, list$1 = node.attributes; i$1 < list$1.length; i$1 += 1) + { + var attr = list$1[i$1]; + + c(attr, st); + } } }; base.ImportExpression = function (node, st, c) { c(node.source, st, "Expression"); + if (node.options) { c(node.options, st, "Expression"); } }; base.ImportSpecifier = base.ImportDefaultSpecifier = base.ImportNamespaceSpecifier = base.Identifier = base.PrivateIdentifier = base.Literal = ignore; diff --git a/deps/acorn/acorn-walk/package.json b/deps/acorn/acorn-walk/package.json index 133059576956d8..362add83801045 100644 --- a/deps/acorn/acorn-walk/package.json +++ b/deps/acorn/acorn-walk/package.json @@ -16,7 +16,7 @@ ], "./package.json": "./package.json" }, - "version": "8.3.4", + "version": "8.3.5", "engines": { "node": ">=0.4.0" },