1+ /**
2+ * @typedef {import('./index.js').KeyFunction } KeyFunction
3+ * @typedef {import('./index.js').TestFunctionAnything } TestFunctionAnything
4+ */
5+
16import test from 'tape'
27import { u } from 'unist-builder'
38import { select } from 'unist-util-select'
@@ -43,10 +48,12 @@ test('Index', function (t) {
4348
4449 t . end ( )
4550
51+ /** @type {KeyFunction } */
4652 function keyFn ( node ) {
4753 return node . id
4854 }
4955
56+ /** @type {TestFunctionAnything } */
5057 function filter ( node ) {
5158 return node . type === 'a'
5259 }
@@ -193,6 +200,7 @@ test('index.get', function (t) {
193200 sst . deepEqual ( index . get ( 'bar' ) , [ select ( 'node[word="bar"]' , ast ) ] )
194201 sst . end ( )
195202
203+ /** @type {TestFunctionAnything } */
196204 function filter ( node , index , parent ) {
197205 return 'word' in node && index < 2 && parent . type === 'root'
198206 }
@@ -202,15 +210,18 @@ test('index.get', function (t) {
202210 } )
203211
204212 t . test ( 'computed keys' , function ( st ) {
213+ /**
214+ * @typedef {{x: number, y: number, z: number} } FunkyNode
215+ */
216+
205217 var ast = u ( 'root' , { x : 0 , y : 4 , id : 0 } , [
206218 u ( 'node' , { x : 3 , y : 2 , id : 1 } ) ,
207219 u ( 'node' , { x : 2 , y : 2 , id : 2 } ) ,
208220 u ( 'node' , { x : 3 , y : 1 , id : 3 } ) ,
209221 u ( 'node' , { x : 4 , y : 1 , id : 4 } )
210222 ] )
211- var index
212-
213- index = new Index ( xPlusY , ast )
223+ // @ts -ignore it’s fine
224+ var index = new Index ( xPlusY , ast )
214225 st . deepEqual ( index . get ( 4 ) , [
215226 select ( '[id=0]' , ast ) ,
216227 select ( '[id=2]' , ast ) ,
@@ -219,13 +230,17 @@ test('index.get', function (t) {
219230 st . deepEqual ( index . get ( 0 ) , [ ] )
220231 st . deepEqual ( index . get ( 5 ) , [ select ( '[id=1]' , ast ) , select ( '[id=4]' , ast ) ] )
221232
233+ // @ts -ignore it’s fine
222234 st . deepEqual ( new Index ( xPlusY , ast , 'node' ) . get ( 4 ) , [
223235 select ( '[id=2]' , ast ) ,
224236 select ( '[id=3]' , ast )
225237 ] )
226238
227239 st . end ( )
228240
241+ /**
242+ * @param {FunkyNode } node
243+ */
229244 function xPlusY ( node ) {
230245 return node . x + node . y
231246 }
0 commit comments