| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,13 @@ | |||
| 1 | + ## 8.3.5 (2026-02-19) | ||
| 2 | + | ||
| 3 | + ### Bug fixes | ||
| 4 | + | ||
| 5 | + Emit a more informative error message when trying to walk a node type that has no walker function. | ||
| 6 | + | ||
| 7 | + Specify callbacks in types to receive `AnyNode` type, so that they can be narrowed more easily. | ||
| 8 | + | ||
| 9 | + Support import attributes. | ||
| 10 | + | ||
| 1 | 11 | ## 8.3.4 (2024-09-09) | |
| 2 | 12 | ||
| 3 | 13 | ### Bug fixes | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,8 +47,8 @@ produce a meaningful state. (An example of a use of state is to track | |||
| 47 | 47 | scope at each point in the tree.) | |
| 48 | 48 | ||
| 49 | 49 | ```js | |
| 50 | - const acorn = require("acorn") | ||
| 51 | - const walk = require("acorn-walk") | ||
| 50 | + import * as acorn from "acorn" | ||
| 51 | + import * as walk from "acorn-walk" | ||
| 52 | 52 | ||
| 53 | 53 | walk.simple(acorn.parse("let x = 10"), { | |
| 54 | 54 | Literal(node) { | |
@@ -62,8 +62,8 @@ a tree, building up an array of ancestor nodes (including the current node) | |||
| 62 | 62 | and passing the array to the callbacks as a third parameter. | |
| 63 | 63 | ||
| 64 | 64 | ```js | |
| 65 | - const acorn = require("acorn") | ||
| 66 | - const walk = require("acorn-walk") | ||
| 65 | + import * as acorn from "acorn" | ||
| 66 | + import * as walk from "acorn-walk" | ||
| 67 | 67 | ||
| 68 | 68 | walk.ancestor(acorn.parse("foo('hi')"), { | |
| 69 | 69 | Literal(_node, _state, ancestors) { | |
@@ -97,8 +97,8 @@ current node) and passing the array to the callbacks as a third | |||
| 97 | 97 | parameter. | |
| 98 | 98 | ||
| 99 | 99 | ```js | |
| 100 | - const acorn = require("acorn") | ||
| 101 | - const walk = require("acorn-walk") | ||
| 100 | + import * as acorn from "acorn" | ||
| 101 | + import * as walk from "acorn-walk" | ||
| 102 | 102 | ||
| 103 | 103 | walk.full(acorn.parse("1 + 1"), node => { | |
| 104 | 104 | console.log(`There's a ${node.type} node at ${node.ch}`) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,15 +1,15 @@ | |||
| 1 | 1 | import * as acorn from "acorn" | |
| 2 | 2 | ||
| 3 | 3 | export type FullWalkerCallback<TState> = ( | |
| 4 | - node: acorn.Node, | ||
| 4 | + node: acorn.AnyNode, | ||
| 5 | 5 | state: TState, | |
| 6 | 6 | type: string | |
| 7 | 7 | ) => void | |
| 8 | 8 | ||
| 9 | 9 | export type FullAncestorWalkerCallback<TState> = ( | |
| 10 | - node: acorn.Node, | ||
| 10 | + node: acorn.AnyNode, | ||
| 11 | 11 | state: TState, | |
| 12 | - ancestors: acorn.Node[], | ||
| 12 | + ancestors: acorn.AnyNode[], | ||
| 13 | 13 | type: string | |
| 14 | 14 | ) => void | |
| 15 | 15 | ||
@@ -29,24 +29,24 @@ export type SimpleVisitors<TState> = { | |||
| 29 | 29 | } | |
| 30 | 30 | ||
| 31 | 31 | 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[] | ||
| 33 | 33 | ) => void | |
| 34 | 34 | } & { | |
| 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 | ||
| 36 | 36 | } | |
| 37 | 37 | ||
| 38 | - export type WalkerCallback<TState> = (node: acorn.Node, state: TState) => void | ||
| 38 | + export type WalkerCallback<TState> = (node: acorn.AnyNode, state: TState) => void | ||
| 39 | 39 | ||
| 40 | 40 | export type RecursiveVisitors<TState> = { | |
| 41 | 41 | [type in acorn.AnyNode["type"]]?: ( node: Extract<acorn.AnyNode, { type: type }>, state: TState, callback: WalkerCallback<TState>) => void | |
| 42 | 42 | } & { | |
| 43 | 43 | [type in keyof AggregateType]?: (node: AggregateType[type], state: TState, callback: WalkerCallback<TState>) => void | |
| 44 | 44 | } | |
| 45 | 45 | ||
| 46 | - export type FindPredicate = (type: string, node: acorn.Node) => boolean | ||
| 46 | + export type FindPredicate = (type: string, node: acorn.AnyNode) => boolean | ||
| 47 | 47 | ||
| 48 | 48 | export interface Found<TState> { | |
| 49 | - node: acorn.Node, | ||
| 49 | + node: acorn.AnyNode, | ||
| 50 | 50 | state: TState | |
| 51 | 51 | } | |
| 52 | 52 | ||
@@ -66,10 +66,6 @@ export function simple<TState>( | |||
| 66 | 66 | ||
| 67 | 67 | /** | |
| 68 | 68 | * 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. | |
| 69 | - * @param node | ||
| 70 | - * @param visitors | ||
| 71 | - * @param base | ||
| 72 | - * @param state | ||
| 73 | 69 | */ | |
| 74 | 70 | export function ancestor<TState>( | |
| 75 | 71 | node: acorn.Node, | |
@@ -94,10 +90,6 @@ export function recursive<TState>( | |||
| 94 | 90 | ||
| 95 | 91 | /** | |
| 96 | 92 | * does a 'full' walk over a tree, calling the {@link callback} with the arguments (node, state, type) for each node | |
| 97 | - * @param node | ||
| 98 | - * @param callback | ||
| 99 | - * @param base | ||
| 100 | - * @param state | ||
| 101 | 93 | */ | |
| 102 | 94 | export function full<TState>( | |
| 103 | 95 | node: acorn.Node, | |
@@ -108,10 +100,6 @@ export function full<TState>( | |||
| 108 | 100 | ||
| 109 | 101 | /** | |
| 110 | 102 | * 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. | |
| 111 | - * @param node | ||
| 112 | - * @param callback | ||
| 113 | - * @param base | ||
| 114 | - * @param state | ||
| 115 | 103 | */ | |
| 116 | 104 | export function fullAncestor<TState>( | |
| 117 | 105 | node: acorn.Node, | |
@@ -122,8 +110,6 @@ export function fullAncestor<TState>( | |||
| 122 | 110 | ||
| 123 | 111 | /** | |
| 124 | 112 | * 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}. | |
| 125 | - * @param functions | ||
| 126 | - * @param base | ||
| 127 | 113 | */ | |
| 128 | 114 | export function make<TState>( | |
| 129 | 115 | functions: RecursiveVisitors<TState>, | |
@@ -132,33 +118,22 @@ export function make<TState>( | |||
| 132 | 118 | ||
| 133 | 119 | /** | |
| 134 | 120 | * 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. | |
| 135 | - * @param node | ||
| 136 | - * @param start | ||
| 137 | - * @param end | ||
| 138 | - * @param type | ||
| 139 | - * @param base | ||
| 140 | - * @param state | ||
| 141 | 121 | */ | |
| 142 | 122 | export function findNodeAt<TState>( | |
| 143 | 123 | node: acorn.Node, | |
| 144 | - start: number | undefined, | ||
| 145 | - end?: number | undefined, | ||
| 124 | + start: number | undefined | null, | ||
| 125 | + end?: number | undefined | null, | ||
| 146 | 126 | type?: FindPredicate | string, | |
| 147 | 127 | base?: RecursiveVisitors<TState>, | |
| 148 | 128 | state?: TState | |
| 149 | 129 | ): Found<TState> | undefined | |
| 150 | 130 | ||
| 151 | 131 | /** | |
| 152 | 132 | * like {@link findNodeAt}, but will match any node that exists 'around' (spanning) the given position. | |
| 153 | - * @param node | ||
| 154 | - * @param start | ||
| 155 | - * @param type | ||
| 156 | - * @param base | ||
| 157 | - * @param state | ||
| 158 | 133 | */ | |
| 159 | 134 | export function findNodeAround<TState>( | |
| 160 | 135 | node: acorn.Node, | |
| 161 | - start: number | undefined, | ||
| 136 | + start: number | undefined | null, | ||
| 162 | 137 | type?: FindPredicate | string, | |
| 163 | 138 | base?: RecursiveVisitors<TState>, | |
| 164 | 139 | state?: TState | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,15 +1,15 @@ | |||
| 1 | 1 | import * as acorn from "acorn" | |
| 2 | 2 | ||
| 3 | 3 | export type FullWalkerCallback<TState> = ( | |
| 4 | - node: acorn.Node, | ||
| 4 | + node: acorn.AnyNode, | ||
| 5 | 5 | state: TState, | |
| 6 | 6 | type: string | |
| 7 | 7 | ) => void | |
| 8 | 8 | ||
| 9 | 9 | export type FullAncestorWalkerCallback<TState> = ( | |
| 10 | - node: acorn.Node, | ||
| 10 | + node: acorn.AnyNode, | ||
| 11 | 11 | state: TState, | |
| 12 | - ancestors: acorn.Node[], | ||
| 12 | + ancestors: acorn.AnyNode[], | ||
| 13 | 13 | type: string | |
| 14 | 14 | ) => void | |
| 15 | 15 | ||
@@ -29,24 +29,24 @@ export type SimpleVisitors<TState> = { | |||
| 29 | 29 | } | |
| 30 | 30 | ||
| 31 | 31 | 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[] | ||
| 33 | 33 | ) => void | |
| 34 | 34 | } & { | |
| 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 | ||
| 36 | 36 | } | |
| 37 | 37 | ||
| 38 | - export type WalkerCallback<TState> = (node: acorn.Node, state: TState) => void | ||
| 38 | + export type WalkerCallback<TState> = (node: acorn.AnyNode, state: TState) => void | ||
| 39 | 39 | ||
| 40 | 40 | export type RecursiveVisitors<TState> = { | |
| 41 | 41 | [type in acorn.AnyNode["type"]]?: ( node: Extract<acorn.AnyNode, { type: type }>, state: TState, callback: WalkerCallback<TState>) => void | |
| 42 | 42 | } & { | |
| 43 | 43 | [type in keyof AggregateType]?: (node: AggregateType[type], state: TState, callback: WalkerCallback<TState>) => void | |
| 44 | 44 | } | |
| 45 | 45 | ||
| 46 | - export type FindPredicate = (type: string, node: acorn.Node) => boolean | ||
| 46 | + export type FindPredicate = (type: string, node: acorn.AnyNode) => boolean | ||
| 47 | 47 | ||
| 48 | 48 | export interface Found<TState> { | |
| 49 | - node: acorn.Node, | ||
| 49 | + node: acorn.AnyNode, | ||
| 50 | 50 | state: TState | |
| 51 | 51 | } | |
| 52 | 52 | ||
@@ -66,10 +66,6 @@ export function simple<TState>( | |||
| 66 | 66 | ||
| 67 | 67 | /** | |
| 68 | 68 | * 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. | |
| 69 | - * @param node | ||
| 70 | - * @param visitors | ||
| 71 | - * @param base | ||
| 72 | - * @param state | ||
| 73 | 69 | */ | |
| 74 | 70 | export function ancestor<TState>( | |
| 75 | 71 | node: acorn.Node, | |
@@ -94,10 +90,6 @@ export function recursive<TState>( | |||
| 94 | 90 | ||
| 95 | 91 | /** | |
| 96 | 92 | * does a 'full' walk over a tree, calling the {@link callback} with the arguments (node, state, type) for each node | |
| 97 | - * @param node | ||
| 98 | - * @param callback | ||
| 99 | - * @param base | ||
| 100 | - * @param state | ||
| 101 | 93 | */ | |
| 102 | 94 | export function full<TState>( | |
| 103 | 95 | node: acorn.Node, | |
@@ -108,10 +100,6 @@ export function full<TState>( | |||
| 108 | 100 | ||
| 109 | 101 | /** | |
| 110 | 102 | * 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. | |
| 111 | - * @param node | ||
| 112 | - * @param callback | ||
| 113 | - * @param base | ||
| 114 | - * @param state | ||
| 115 | 103 | */ | |
| 116 | 104 | export function fullAncestor<TState>( | |
| 117 | 105 | node: acorn.Node, | |
@@ -122,8 +110,6 @@ export function fullAncestor<TState>( | |||
| 122 | 110 | ||
| 123 | 111 | /** | |
| 124 | 112 | * 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}. | |
| 125 | - * @param functions | ||
| 126 | - * @param base | ||
| 127 | 113 | */ | |
| 128 | 114 | export function make<TState>( | |
| 129 | 115 | functions: RecursiveVisitors<TState>, | |
@@ -132,33 +118,22 @@ export function make<TState>( | |||
| 132 | 118 | ||
| 133 | 119 | /** | |
| 134 | 120 | * 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. | |
| 135 | - * @param node | ||
| 136 | - * @param start | ||
| 137 | - * @param end | ||
| 138 | - * @param type | ||
| 139 | - * @param base | ||
| 140 | - * @param state | ||
| 141 | 121 | */ | |
| 142 | 122 | export function findNodeAt<TState>( | |
| 143 | 123 | node: acorn.Node, | |
| 144 | - start: number | undefined, | ||
| 145 | - end?: number | undefined, | ||
| 124 | + start: number | undefined | null, | ||
| 125 | + end?: number | undefined | null, | ||
| 146 | 126 | type?: FindPredicate | string, | |
| 147 | 127 | base?: RecursiveVisitors<TState>, | |
| 148 | 128 | state?: TState | |
| 149 | 129 | ): Found<TState> | undefined | |
| 150 | 130 | ||
| 151 | 131 | /** | |
| 152 | 132 | * like {@link findNodeAt}, but will match any node that exists 'around' (spanning) the given position. | |
| 153 | - * @param node | ||
| 154 | - * @param start | ||
| 155 | - * @param type | ||
| 156 | - * @param base | ||
| 157 | - * @param state | ||
| 158 | 133 | */ | |
| 159 | 134 | export function findNodeAround<TState>( | |
| 160 | 135 | node: acorn.Node, | |
| 161 | - start: number | undefined, | ||
| 136 | + start: number | undefined | null, | ||
| 162 | 137 | type?: FindPredicate | string, | |
| 163 | 138 | base?: RecursiveVisitors<TState>, | |
| 164 | 139 | state?: TState | |
| Back | FazBrowse Home | New Git URL |
0 commit comments