@@ -10,30 +10,33 @@ import {u} from 'unist-builder'
1010import { map } from './index.js'
1111
1212test ( 'unist-util-map' , function ( t ) {
13+ /** @type {Root } */
14+ const rootA = u ( 'root' , [ u ( 'node' , [ u ( 'leaf' , '1' ) ] ) , u ( 'leaf' , '2' ) ] )
1315 t . deepEqual (
14- map ( u ( 'root' , [ u ( 'node' , [ u ( 'leaf' , '1' ) ] ) , u ( 'leaf' , '2' ) ] ) , changeLeaf ) ,
16+ map ( rootA , changeLeaf ) ,
1517 u ( 'root' , [ u ( 'node' , [ u ( 'leaf' , 'CHANGED' ) ] ) , u ( 'leaf' , 'CHANGED' ) ] ) ,
1618 'should map the specified node'
1719 )
1820
21+ /** @type {Root } */
22+ const rootB = {
23+ type : 'root' ,
24+ children : [
25+ { type : 'node' , children : [ { type : 'leaf' , value : '1' } ] } ,
26+ { type : 'leaf' , value : '2' }
27+ ]
28+ }
1929 t . deepEqual (
20- map (
21- /** @type {Root } */
22- ( {
23- type : 'root' ,
24- children : [
25- { type : 'node' , children : [ { type : 'leaf' , value : '1' } ] } ,
26- { type : 'leaf' , value : '2' }
27- ]
28- } ) ,
29- changeLeaf
30- ) ,
30+ map ( rootB , changeLeaf ) ,
3131 u ( 'root' , [ u ( 'node' , [ u ( 'leaf' , 'CHANGED' ) ] ) , u ( 'leaf' , 'CHANGED' ) ] ) ,
3232 'should map the specified node'
3333 )
3434
35+ /** @type {Root } */
36+ const rootC = u ( 'root' , [ u ( 'node' , [ u ( 'leaf' , '1' ) ] ) , u ( 'leaf' , '2' ) ] )
3537 t . deepEqual (
36- map ( u ( 'root' , [ u ( 'node' , [ u ( 'leaf' , '1' ) ] ) , u ( 'leaf' , '2' ) ] ) , nullLeaf ) ,
38+ // @ts -expect-error: invalid:
39+ map ( rootC , nullLeaf ) ,
3740 // @ts -expect-error: not valid but tested anyway.
3841 u ( 'root' , [ u ( 'node' , [ { } ] ) , { } ] ) ,
3942 'should work when retuning an empty object'
@@ -66,23 +69,23 @@ test('unist-util-map', function (t) {
6669 ? Object . assign ( { } , node , { value : 'CHANGED' } )
6770 : node
6871 }
72+ } )
6973
70- /**
71- * @param {AnyNode } node
72- * @returns {AnyNode? }
73- */
74- function nullLeaf ( node ) {
75- return node . type === 'leaf' ? null : node
76- }
74+ /**
75+ * @param {AnyNode } node
76+ * @returns {Root | Node | null }
77+ */
78+ function nullLeaf ( node ) {
79+ return node . type === 'leaf' ? null : node
80+ }
7781
78- function addValue ( ) {
79- return { value : 'test' }
80- }
82+ function addValue ( ) {
83+ return { value : 'test' }
84+ }
8185
82- /**
83- * @type {import('./index.js').MapFunction<Root> }
84- */
85- function asIs ( node ) {
86- return node
87- }
88- } )
86+ /**
87+ * @type {import('./index.js').MapFunction<Root> }
88+ */
89+ function asIs ( node ) {
90+ return node
91+ }
0 commit comments