Skip to content

Commit 29ba9e9

Browse files
committed
Add VisitorResult type
1 parent dcd1d82 commit 29ba9e9

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
/**
22
* @typedef {import('unist').Node} Node
33
* @typedef {import('unist').Parent} Parent
4-
*
5-
* @typedef {import('unist-util-is').Type} Type
6-
* @typedef {import('unist-util-is').Props} Props
7-
* @typedef {import('unist-util-is').TestFunctionAnything} TestFunctionAnything
4+
* @typedef {import('unist-util-is').Test} Test
85
*/
96

107
/**
118
* @typedef {CONTINUE|SKIP|EXIT} Action Union of the action types
129
* @typedef {number} Index Move to the sibling at index next (after node itself is completely traversed). Useful if mutating the tree, such as removing the node the visitor is currently on, or any of its previous siblings (or next siblings, in case of reverse) Results less than 0 or greater than or equal to children.length stop traversing the parent
1310
* @typedef {[(Action|null|undefined|void)?, (Index|null|undefined)?]} ActionTuple List with one or two values, the first an action, the second an index.
11+
* @typedef {null|undefined|Action|Index|ActionTuple|void} VisitorResult Any value that can be returned from a visitor
1412
*/
1513

1614
/**
@@ -28,7 +26,7 @@
2826
* @callback Visitor
2927
* @param {V} node Found node
3028
* @param {Array.<Parent>} ancestors Ancestors of node
31-
* @returns {null|undefined|Action|Index|ActionTuple|void}
29+
* @returns {VisitorResult}
3230
*/
3331

3432
import {convert} from 'unist-util-is'
@@ -51,7 +49,7 @@ export const visitParents =
5149
/**
5250
* @type {(
5351
* (<T extends Node>(tree: Node, test: T['type']|Partial<T>|import('unist-util-is').TestFunctionPredicate<T>|Array.<T['type']|Partial<T>|import('unist-util-is').TestFunctionPredicate<T>>, visitor: Visitor<T>, reverse?: boolean) => void) &
54-
* ((tree: Node, test: null|undefined|Type|Props|TestFunctionAnything|Array<Type|Props|TestFunctionAnything>, visitor: Visitor<Node>, reverse?: boolean) => void) &
52+
* ((tree: Node, test: Test, visitor: Visitor<Node>, reverse?: boolean) => void) &
5553
* ((tree: Node, visitor: Visitor<Node>, reverse?: boolean) => void)
5654
* )}
5755
*/
@@ -60,7 +58,7 @@ export const visitParents =
6058
* Visit children of tree which pass a test
6159
*
6260
* @param {Node} tree Abstract syntax tree to walk
63-
* @param {null|undefined|Type|Props|TestFunctionAnything|Array<Type|Props|TestFunctionAnything>} test test Test node
61+
* @param {Test} test test Test node
6462
* @param {Visitor<Node>} visitor Function to run for each node
6563
* @param {boolean} [reverse] Fisit the tree in reverse, defaults to false
6664
*/
@@ -146,7 +144,7 @@ export const visitParents =
146144
)
147145

148146
/**
149-
* @param {null|undefined|void|Action|Index|ActionTuple} value
147+
* @param {VisitorResult} value
150148
* @returns {ActionTuple}
151149
*/
152150
function toResult(value) {

0 commit comments

Comments
 (0)