1
+ /**
2
+ * @typedef {import('unist').Literal<number> } ExampleLiteral
3
+ * @typedef {import('unist').Parent<ExampleLiteral> } ExampleParent
4
+ */
5
+
1
6
import test from 'tape'
2
7
import { modifyChildren } from './index.js'
3
8
@@ -6,7 +11,7 @@ function noop() {}
6
11
test ( 'modifyChildren()' , function ( t ) {
7
12
t . throws (
8
13
function ( ) {
9
- // @ts -ignore runtime.
14
+ // @ts -expect-error runtime.
10
15
modifyChildren ( noop ) ( )
11
16
} ,
12
17
/ M i s s i n g c h i l d r e n i n ` p a r e n t ` / ,
@@ -15,7 +20,7 @@ test('modifyChildren()', function (t) {
15
20
16
21
t . throws (
17
22
function ( ) {
18
- // @ts -ignore runtime.
23
+ // @ts -expect-error runtime.
19
24
modifyChildren ( noop ) ( { } )
20
25
} ,
21
26
/ M i s s i n g c h i l d r e n i n ` p a r e n t ` / ,
@@ -54,7 +59,11 @@ test('modifyChildren()', function (t) {
54
59
]
55
60
var n = - 1
56
61
57
- modifyChildren ( function ( child , index , parent ) {
62
+ modifyChildren ( function (
63
+ /** @type {ExampleLiteral } */ child ,
64
+ index ,
65
+ /** @type {ExampleParent } */ parent
66
+ ) {
58
67
n ++
59
68
60
69
if ( index < 3 ) {
@@ -63,15 +72,17 @@ test('modifyChildren()', function (t) {
63
72
64
73
st . deepEqual ( child , children [ n ] )
65
74
st . deepEqual ( index , n )
66
- } ) ( {
67
- type : 'y' ,
68
- children : [
69
- { type : 'x' , value : 0 } ,
70
- { type : 'x' , value : 1 } ,
71
- { type : 'x' , value : 2 } ,
72
- { type : 'x' , value : 3 }
73
- ]
74
- } )
75
+ } ) (
76
+ /** @type {ExampleParent } */ ( {
77
+ type : 'y' ,
78
+ children : [
79
+ { type : 'x' , value : 0 } ,
80
+ { type : 'x' , value : 1 } ,
81
+ { type : 'x' , value : 2 } ,
82
+ { type : 'x' , value : 3 }
83
+ ]
84
+ } )
85
+ )
75
86
76
87
st . end ( )
77
88
} )
@@ -93,7 +104,11 @@ test('modifyChildren()', function (t) {
93
104
]
94
105
}
95
106
96
- modifyChildren ( function ( child , index , parent ) {
107
+ modifyChildren ( function (
108
+ /** @type {ExampleLiteral } */ child ,
109
+ index ,
110
+ /** @type {ExampleParent } */ parent
111
+ ) {
97
112
st . deepEqual ( child , children [ ++ n ] )
98
113
99
114
if ( child . value === 1 ) {
@@ -129,7 +144,11 @@ test('modifyChildren()', function (t) {
129
144
}
130
145
var inserted = false
131
146
132
- modifyChildren ( function ( child , _ , parent ) {
147
+ modifyChildren ( function (
148
+ /** @type {ExampleLiteral } */ child ,
149
+ _ ,
150
+ /** @type {ExampleParent } */ parent
151
+ ) {
133
152
st . deepEqual ( child , calls [ ++ n ] )
134
153
135
154
if ( ! inserted && child . value === 1 ) {
0 commit comments