@@ -8,9 +8,9 @@ import {modifyChildren} from './index.js'
8
8
9
9
function noop ( ) { }
10
10
11
- test ( 'modifyChildren()' , function ( t ) {
11
+ test ( 'modifyChildren()' , ( t ) => {
12
12
t . throws (
13
- function ( ) {
13
+ ( ) => {
14
14
// @ts -expect-error runtime.
15
15
modifyChildren ( noop ) ( )
16
16
} ,
@@ -19,25 +19,25 @@ test('modifyChildren()', function (t) {
19
19
)
20
20
21
21
t . throws (
22
- function ( ) {
22
+ ( ) => {
23
23
// @ts -expect-error runtime.
24
24
modifyChildren ( noop ) ( { } )
25
25
} ,
26
26
/ M i s s i n g c h i l d r e n i n ` p a r e n t ` / ,
27
27
'should throw without parent'
28
28
)
29
29
30
- t . test ( 'should invoke `fn` for each child in `parent`' , function ( st ) {
31
- var children = [
30
+ t . test ( 'should invoke `fn` for each child in `parent`' , ( st ) => {
31
+ const children = [
32
32
{ type : 'x' , value : 0 } ,
33
33
{ type : 'x' , value : 1 } ,
34
34
{ type : 'x' , value : 2 } ,
35
35
{ type : 'x' , value : 3 }
36
36
]
37
- var context = { type : 'y' , children}
38
- var n = - 1
37
+ const context = { type : 'y' , children}
38
+ let n = - 1
39
39
40
- modifyChildren ( function ( child , index , parent ) {
40
+ modifyChildren ( ( child , index , parent ) => {
41
41
n ++
42
42
st . strictEqual ( child , children [ n ] )
43
43
st . strictEqual ( index , n )
@@ -47,8 +47,8 @@ test('modifyChildren()', function (t) {
47
47
st . end ( )
48
48
} )
49
49
50
- t . test ( 'should work when new children are added' , function ( st ) {
51
- var children = [
50
+ t . test ( 'should work when new children are added' , ( st ) => {
51
+ const children = [
52
52
{ type : 'x' , value : 0 } ,
53
53
{ type : 'x' , value : 1 } ,
54
54
{ type : 'x' , value : 2 } ,
@@ -57,22 +57,24 @@ test('modifyChildren()', function (t) {
57
57
{ type : 'x' , value : 5 } ,
58
58
{ type : 'x' , value : 6 }
59
59
]
60
- var n = - 1
61
-
62
- modifyChildren ( function (
63
- /** @type {ExampleLiteral } */ child ,
64
- index ,
65
- /** @type {ExampleParent } */ parent
66
- ) {
67
- n ++
68
-
69
- if ( index < 3 ) {
70
- parent . children . push ( { type : 'x' , value : parent . children . length } )
60
+ let n = - 1
61
+
62
+ modifyChildren (
63
+ (
64
+ /** @type {ExampleLiteral } */ child ,
65
+ index ,
66
+ /** @type {ExampleParent } */ parent
67
+ ) => {
68
+ n ++
69
+
70
+ if ( index < 3 ) {
71
+ parent . children . push ( { type : 'x' , value : parent . children . length } )
72
+ }
73
+
74
+ st . deepEqual ( child , children [ n ] )
75
+ st . deepEqual ( index , n )
71
76
}
72
-
73
- st . deepEqual ( child , children [ n ] )
74
- st . deepEqual ( index , n )
75
- } ) (
77
+ ) (
76
78
/** @type {ExampleParent } */ ( {
77
79
type : 'y' ,
78
80
children : [
@@ -87,15 +89,15 @@ test('modifyChildren()', function (t) {
87
89
st . end ( )
88
90
} )
89
91
90
- t . test ( 'should skip forwards' , function ( st ) {
91
- var children = [
92
+ t . test ( 'should skip forwards' , ( st ) => {
93
+ const children = [
92
94
{ type : 'x' , value : 0 } ,
93
95
{ type : 'x' , value : 1 } ,
94
96
{ type : 'x' , value : 2 } ,
95
97
{ type : 'x' , value : 3 }
96
98
]
97
- var n = - 1
98
- var context = {
99
+ let n = - 1
100
+ const context = {
99
101
type : 'y' ,
100
102
children : [
101
103
{ type : 'x' , value : 0 } ,
@@ -104,26 +106,28 @@ test('modifyChildren()', function (t) {
104
106
]
105
107
}
106
108
107
- modifyChildren ( function (
108
- /** @type {ExampleLiteral } */ child ,
109
- index ,
110
- /** @type {ExampleParent } */ parent
111
- ) {
112
- st . deepEqual ( child , children [ ++ n ] )
113
-
114
- if ( child . value === 1 ) {
115
- parent . children . splice ( index + 1 , 0 , { type : 'x' , value : 2 } )
116
- return index + 1
109
+ modifyChildren (
110
+ (
111
+ /** @type {ExampleLiteral } */ child ,
112
+ index ,
113
+ /** @type {ExampleParent } */ parent
114
+ ) => {
115
+ st . deepEqual ( child , children [ ++ n ] )
116
+
117
+ if ( child . value === 1 ) {
118
+ parent . children . splice ( index + 1 , 0 , { type : 'x' , value : 2 } )
119
+ return index + 1
120
+ }
117
121
}
118
- } ) ( context )
122
+ ) ( context )
119
123
120
124
st . deepEqual ( context . children , children )
121
125
122
126
st . end ( )
123
127
} )
124
128
125
- t . test ( 'should skip backwards' , function ( st ) {
126
- var calls = [
129
+ t . test ( 'should skip backwards' , ( st ) => {
130
+ const calls = [
127
131
{ type : 'x' , value : 0 } ,
128
132
{ type : 'x' , value : 1 } ,
129
133
{ type : 'x' , value : - 1 } ,
@@ -132,8 +136,8 @@ test('modifyChildren()', function (t) {
132
136
{ type : 'x' , value : 2 } ,
133
137
{ type : 'x' , value : 3 }
134
138
]
135
- var n = - 1
136
- var context = {
139
+ let n = - 1
140
+ const context = {
137
141
type : 'y' ,
138
142
children : [
139
143
{ type : 'x' , value : 0 } ,
@@ -142,21 +146,23 @@ test('modifyChildren()', function (t) {
142
146
{ type : 'x' , value : 3 }
143
147
]
144
148
}
145
- var inserted = false
146
-
147
- modifyChildren ( function (
148
- /** @type {ExampleLiteral } */ child ,
149
- _ ,
150
- /** @type {ExampleParent } */ parent
151
- ) {
152
- st . deepEqual ( child , calls [ ++ n ] )
153
-
154
- if ( ! inserted && child . value === 1 ) {
155
- inserted = true
156
- parent . children . unshift ( { type : 'x' , value : - 1 } )
157
- return - 1
149
+ let inserted = false
150
+
151
+ modifyChildren (
152
+ (
153
+ /** @type {ExampleLiteral } */ child ,
154
+ _ ,
155
+ /** @type {ExampleParent } */ parent
156
+ ) => {
157
+ st . deepEqual ( child , calls [ ++ n ] )
158
+
159
+ if ( ! inserted && child . value === 1 ) {
160
+ inserted = true
161
+ parent . children . unshift ( { type : 'x' , value : - 1 } )
162
+ return - 1
163
+ }
158
164
}
159
- } ) ( context )
165
+ ) ( context )
160
166
161
167
st . deepEqual ( context . children , [
162
168
{ type : 'x' , value : - 1 } ,
0 commit comments