1
1
/**
2
- * @typedef {import('unist').Parent } Parent
3
- * @typedef {import('unist').Node } Node
4
- *
2
+ * @typedef {import('unist').Parent } UnistParent
3
+ * @typedef {import('unist').Node } UnistNode
4
+ */
5
+
6
+ /**
7
+ * @template {UnistParent} Parent
5
8
* @callback Modifier
6
9
* Callback called for each `child` in `parent` later given to `modify`.
7
- * @param {Node } node
10
+ * @param {Parent['children'][number] } node
8
11
* Child of `parent`.
9
12
* @param {number } index
10
13
* Position of `child` in `parent`.
11
14
* @param {Parent } parent
12
15
* Parent node.
13
16
* @returns {number|void }
14
17
* Position to move to next.
15
- *
18
+ */
19
+
20
+ /**
21
+ * @template {UnistParent} Parent
16
22
* @callback Modify
17
23
* Modify children of `parent`.
18
24
* @param {Parent } node
@@ -27,15 +33,16 @@ import {arrayIterate} from 'array-iterate'
27
33
* Wrap `modifier` to be called for each child in the nodes later given to
28
34
* `modify`.
29
35
*
30
- * @param {Modifier } modifier
36
+ * @template {UnistParent} Parent
37
+ * @param {Modifier<Parent> } modifier
31
38
* Callback called for each `child` in `parent` later given to `modify`.
32
- * @returns {Modify }
39
+ * @returns {Modify<Parent> }
33
40
* Modify children of `parent`.
34
41
*/
35
42
export function modifyChildren ( modifier ) {
36
43
return modify
37
44
38
- /** @type {Modify } */
45
+ /** @type {Modify<UnistParent> } */
39
46
function modify ( parent ) {
40
47
if ( ! parent || ! parent . children ) {
41
48
throw new Error ( 'Missing children in `parent` for `modifier`' )
@@ -48,7 +55,7 @@ export function modifyChildren(modifier) {
48
55
* Pass the context as the third argument to `modifier`.
49
56
*
50
57
* @this {Parent}
51
- * @param {Node } node
58
+ * @param {UnistNode } node
52
59
* @param {number } index
53
60
*/
54
61
function iteratee ( node , index ) {
0 commit comments