Skip to content

Commit a45063d

Browse files
authored
Improve types to base what visitor gets on tree
Closes GH-4.
1 parent cf764a5 commit a45063d

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

index.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@
44
*
55
* @typedef {import('unist-util-is').Type} Type
66
* @typedef {import('unist-util-is').Props} Props
7-
* @typedef {import('unist-util-is').TestFunctionAnything} TestFunctionAnything
7+
*/
8+
9+
/**
10+
* Check if a node passes a test
11+
*
12+
* @template {Node} Tree Node type that is checked.
13+
* @callback TestFunction
14+
* @param {Tree} node
15+
* @param {number|null|undefined} [index]
16+
* @param {Parent|null|undefined} [parent]
17+
* @returns {boolean|void}
818
*/
919

1020
/**
@@ -20,8 +30,8 @@ const empty = []
2030
export const remove =
2131
/**
2232
* @type {(
23-
* (<T extends Node>(node: T, options: RemoveOptions, test: Type|Props|TestFunctionAnything|Array<Type|Props|TestFunctionAnything>) => T|null) &
24-
* (<T extends Node>(node: T, test: Type|Props|TestFunctionAnything|Array<Type|Props|TestFunctionAnything>) => T|null)
33+
* (<Tree extends Node>(node: Tree, options: RemoveOptions, test: Type|Props|TestFunction<import('unist-util-visit-parents/complex-types').InclusiveDescendant<Tree>>|Array<Type|Props|TestFunction<import('unist-util-visit-parents/complex-types').InclusiveDescendant<Tree>>>) => Tree|null) &
34+
* (<Tree extends Node>(node: Tree, test: Type|Props|TestFunction<import('unist-util-visit-parents/complex-types').InclusiveDescendant<Tree>>|Array<Type|Props|TestFunction<import('unist-util-visit-parents/complex-types').InclusiveDescendant<Tree>>>) => Tree|null)
2535
* )}
2636
*/
2737
(
@@ -31,7 +41,7 @@ export const remove =
3141
*
3242
* @param {Node} tree Tree to filter
3343
* @param {RemoveOptions} options Whether to drop parent nodes if they had children, but all their children were filtered out. Default is `{cascade: true}`
34-
* @param {Type|Props|TestFunctionAnything|Array<Type|Props|TestFunctionAnything>} test is-compatible test (such as a type)
44+
* @param {Type|Props|TestFunction<Node>|Array<Type|Props|TestFunction<Node>>} test is-compatible test (such as a type)
3545
* @returns {Node|null}
3646
*/
3747
function (tree, options, test) {

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
],
4040
"dependencies": {
4141
"@types/unist": "^2.0.0",
42-
"unist-util-is": "^5.0.0"
42+
"unist-util-is": "^5.0.0",
43+
"unist-util-visit-parents": "^5.0.0"
4344
},
4445
"devDependencies": {
4546
"@types/tape": "^4.0.0",

0 commit comments

Comments
 (0)