1
1
/**
2
2
* @typedef {import('unist').Node } Node
3
3
* @typedef {import('unist').Parent } Parent
4
- *
5
- * @typedef {string } Type
6
- * @typedef {Record<string, unknown> } Props
4
+ * @typedef {import('unist-util-is').Test } Test
7
5
*
8
6
* @typedef Options
9
- * @property {boolean } [cascade=true]
7
+ * Configuration.
8
+ * @property {boolean | null | undefined } [cascade=true]
10
9
* Whether to drop parent nodes if they had children, but all their children
11
10
* were filtered out.
12
- *
13
- * @typedef {Options } RemoveOptions
14
- * @deprecated
15
- * Use `Options` instead.
16
- */
17
-
18
- /**
19
- * Check if a node passes a test.
20
- *
21
- * @template {Node} Tree
22
- * Node type that is checked for.
23
- * @callback TestFunction
24
- * @param {Tree } node
25
- * @param {number|null|undefined } [index]
26
- * @param {Parent|null|undefined } [parent]
27
- * @returns {boolean|void }
28
11
*/
29
12
30
13
import { convert } from 'unist-util-is'
@@ -39,28 +22,29 @@ const empty = []
39
22
*
40
23
* @param tree
41
24
* Tree to change.
42
- * @param [ options]
25
+ * @param options
43
26
* Configuration (optional).
44
- * @param [ test]
27
+ * @param test
45
28
* `unist-util-is`-compatible test.
46
29
* @returns
47
30
* The given `tree` without nodes that pass `test`.
31
+ *
48
32
* `null` is returned if `tree` itself didn’t pass the test or is cascaded
49
33
* away.
50
34
*/
51
35
export const remove =
52
36
/**
53
37
* @type {(
54
- * (<Tree extends Node>(node: Tree, options: RemoveOptions , test: Type|Props|TestFunction<import('unist-util-visit-parents/complex-types.js').InclusiveDescendant<Tree>>|Array<Type|Props|TestFunction<import('unist-util-visit-parents/complex-types.js').InclusiveDescendant<Tree>>>) => Tree| null) &
55
- * (<Tree extends Node>(node: Tree, test: Type|Props|TestFunction<import('unist-util-visit-parents/complex-types.js').InclusiveDescendant<Tree>>|Array<Type|Props|TestFunction<import('unist-util-visit-parents/complex-types.js').InclusiveDescendant<Tree>>>) => Tree| null)
38
+ * (<Tree extends Node>(node: Tree, options: Options , test: Test) => Tree | null) &
39
+ * (<Tree extends Node>(node: Tree, test: Test) => Tree | null)
56
40
* )}
57
41
*/
58
42
(
59
43
/**
60
44
* @param {Node } tree
61
- * @param {RemoveOptions } [options]
62
- * @param {Type|Props|TestFunction<Node>|Array<Type|Props|TestFunction<Node>> } [test]
63
- * @returns {Node| null }
45
+ * @param {Options | null | undefined } [options]
46
+ * @param {Test | null | undefined } [test]
47
+ * @returns {Node | null }
64
48
*/
65
49
function ( tree , options , test ) {
66
50
const is = convert ( test || options )
@@ -76,9 +60,9 @@ export const remove =
76
60
* For each composite node, modify its children array in-place.
77
61
*
78
62
* @param {Node } node
79
- * @param {number| undefined } [index]
80
- * @param {Parent| undefined } [parent]
81
- * @returns {Node| null }
63
+ * @param {number | null | undefined } [index]
64
+ * @param {Parent | null | undefined } [parent]
65
+ * @returns {Node | null }
82
66
*/
83
67
function preorder ( node , index , parent ) {
84
68
/** @type {Array<Node> } */
0 commit comments