1
+ /**
2
+ * @typedef {import('./index.js').KeyFunction } KeyFunction
3
+ * @typedef {import('./index.js').TestFunctionAnything } TestFunctionAnything
4
+ */
5
+
1
6
import test from 'tape'
2
7
import { u } from 'unist-builder'
3
8
import { select } from 'unist-util-select'
@@ -43,10 +48,12 @@ test('Index', function (t) {
43
48
44
49
t . end ( )
45
50
51
+ /** @type {KeyFunction } */
46
52
function keyFn ( node ) {
47
53
return node . id
48
54
}
49
55
56
+ /** @type {TestFunctionAnything } */
50
57
function filter ( node ) {
51
58
return node . type === 'a'
52
59
}
@@ -193,6 +200,7 @@ test('index.get', function (t) {
193
200
sst . deepEqual ( index . get ( 'bar' ) , [ select ( 'node[word="bar"]' , ast ) ] )
194
201
sst . end ( )
195
202
203
+ /** @type {TestFunctionAnything } */
196
204
function filter ( node , index , parent ) {
197
205
return 'word' in node && index < 2 && parent . type === 'root'
198
206
}
@@ -202,15 +210,18 @@ test('index.get', function (t) {
202
210
} )
203
211
204
212
t . test ( 'computed keys' , function ( st ) {
213
+ /**
214
+ * @typedef {{x: number, y: number, z: number} } FunkyNode
215
+ */
216
+
205
217
var ast = u ( 'root' , { x : 0 , y : 4 , id : 0 } , [
206
218
u ( 'node' , { x : 3 , y : 2 , id : 1 } ) ,
207
219
u ( 'node' , { x : 2 , y : 2 , id : 2 } ) ,
208
220
u ( 'node' , { x : 3 , y : 1 , id : 3 } ) ,
209
221
u ( 'node' , { x : 4 , y : 1 , id : 4 } )
210
222
] )
211
- var index
212
-
213
- index = new Index ( xPlusY , ast )
223
+ // @ts -ignore it’s fine
224
+ var index = new Index ( xPlusY , ast )
214
225
st . deepEqual ( index . get ( 4 ) , [
215
226
select ( '[id=0]' , ast ) ,
216
227
select ( '[id=2]' , ast ) ,
@@ -219,13 +230,17 @@ test('index.get', function (t) {
219
230
st . deepEqual ( index . get ( 0 ) , [ ] )
220
231
st . deepEqual ( index . get ( 5 ) , [ select ( '[id=1]' , ast ) , select ( '[id=4]' , ast ) ] )
221
232
233
+ // @ts -ignore it’s fine
222
234
st . deepEqual ( new Index ( xPlusY , ast , 'node' ) . get ( 4 ) , [
223
235
select ( '[id=2]' , ast ) ,
224
236
select ( '[id=3]' , ast )
225
237
] )
226
238
227
239
st . end ( )
228
240
241
+ /**
242
+ * @param {FunkyNode } node
243
+ */
229
244
function xPlusY ( node ) {
230
245
return node . x + node . y
231
246
}
0 commit comments