@@ -9,11 +9,11 @@ import {u} from 'unist-builder'
99import { select } from 'unist-util-select'
1010import { Index } from './index.js'
1111
12- test ( 'Index' , function ( t ) {
13- var node = { type : 'a' , id : 1 }
14- var alt = { type : 'b' , id : 1 }
15- var tree = { type : 'root' , children : [ node , alt ] }
16- var instance = new Index ( 'id' )
12+ test ( 'Index' , ( t ) => {
13+ const node = { type : 'a' , id : 1 }
14+ const alt = { type : 'b' , id : 1 }
15+ const tree = { type : 'root' , children : [ node , alt ] }
16+ let instance = new Index ( 'id' )
1717 instance . add ( node )
1818
1919 t . deepEqual (
@@ -55,14 +55,14 @@ test('Index', function (t) {
5555 t . end ( )
5656} )
5757
58- test ( 'index.add' , function ( t ) {
59- var ast = u ( 'root' , [ u ( 'node' , { word : 'foo' } ) , u ( 'node' , { word : 'bar' } ) ] )
60- var extraNode = u ( 'node' , { word : 'foo' } )
58+ test ( 'index.add' , ( t ) => {
59+ const ast = u ( 'root' , [ u ( 'node' , { word : 'foo' } ) , u ( 'node' , { word : 'bar' } ) ] )
60+ const extraNode = u ( 'node' , { word : 'foo' } )
6161
62- var index = new Index ( 'word' , ast )
62+ const index = new Index ( 'word' , ast )
6363 t . deepEqual ( index . get ( 'foo' ) , [ select ( '[word=foo]' , ast ) ] )
6464
65- var result = index . add ( extraNode )
65+ const result = index . add ( extraNode )
6666 t . deepEqual ( index . get ( 'foo' ) , [ select ( '[word=foo]' , ast ) , extraNode ] )
6767
6868 t . equal ( result , index , 'returns this' )
@@ -76,9 +76,9 @@ test('index.add', function (t) {
7676 t . end ( )
7777} )
7878
79- test ( 'index.get' , function ( t ) {
80- t . test ( 'get' , function ( st ) {
81- var ast = u ( 'node' , { color : 'black' , id : 0 } , [
79+ test ( 'index.get' , ( t ) => {
80+ t . test ( 'get' , ( st ) => {
81+ const ast = u ( 'node' , { color : 'black' , id : 0 } , [
8282 u ( 'node' , { color : 'black' , id : 1 } , [
8383 u ( 'node' , { color : 'red' , id : 2 } , [
8484 u ( 'node' , { color : 'black' , id : 3 } ) ,
@@ -101,7 +101,7 @@ test('index.get', function (t) {
101101 ] )
102102 ] )
103103
104- var index = new Index ( 'color' , ast )
104+ const index = new Index ( 'color' , ast )
105105
106106 st . deepEqual ( index . get ( 'black' ) , [
107107 select ( '[id=0]' , ast ) ,
@@ -129,32 +129,32 @@ test('index.get', function (t) {
129129 st . end ( )
130130 } )
131131
132- t . test ( 'degenerate keys' , function ( st ) {
133- st . test ( 'Object.prototype keys' , function ( sst ) {
134- var ast = u ( 'node' , { word : '__proto__' , id : 0 } , [
132+ t . test ( 'degenerate keys' , ( st ) => {
133+ st . test ( 'Object.prototype keys' , ( sst ) => {
134+ const ast = u ( 'node' , { word : '__proto__' , id : 0 } , [
135135 u ( 'node' , { word : 'constructor' , id : 1 } ) ,
136136 u ( 'node' , { word : 'toString' , id : 2 } )
137137 ] )
138- var index = new Index ( 'word' , ast )
138+ const index = new Index ( 'word' , ast )
139139
140140 sst . deepEqual ( index . get ( '__proto__' ) , [ select ( '[id=0]' , ast ) ] )
141141 sst . deepEqual ( index . get ( 'constructor' ) , [ select ( '[id=1]' , ast ) ] )
142142 sst . deepEqual ( index . get ( 'toString' ) , [ select ( '[id=2]' , ast ) ] )
143143 sst . end ( )
144144 } )
145145
146- st . test ( 'identity keys' , function ( sst ) {
147- var id1 = { foo : 'bar' }
148- var id2 = { foo : 'bar' }
149- var ast = u ( 'root' , [
146+ st . test ( 'identity keys' , ( sst ) => {
147+ const id1 = { foo : 'bar' }
148+ const id2 = { foo : 'bar' }
149+ const ast = u ( 'root' , [
150150 u ( 'node' , { word : false , id : 0 } ) ,
151151 u ( 'node' , { word : 'false' , id : 1 } ) ,
152152 u ( 'node' , { word : 1 , id : 2 } ) ,
153153 u ( 'node' , { word : '1' , id : 3 } ) ,
154154 u ( 'node' , { word : id1 , id : 4 } ) ,
155155 u ( 'node' , { word : id2 , id : 5 } )
156156 ] )
157- var index = new Index ( 'word' , ast )
157+ const index = new Index ( 'word' , ast )
158158
159159 sst . deepEqual ( index . get ( false ) , [ select ( '[id=0]' , ast ) ] )
160160 sst . deepEqual ( index . get ( 'false' ) , [ select ( '[id=1]' , ast ) ] )
@@ -169,29 +169,29 @@ test('index.get', function (t) {
169169 st . end ( )
170170 } )
171171
172- t . test ( 'empty index' , function ( st ) {
172+ t . test ( 'empty index' , ( st ) => {
173173 st . deepEqual ( new Index ( 'foo' , null ) . get ( 'bar' ) , [ ] )
174174 st . deepEqual ( new Index ( 'foo' ) . get ( 'bar' ) , [ ] )
175175 st . end ( )
176176 } )
177177
178- t . test ( 'Index filter' , function ( st ) {
179- var ast = u ( 'root' , [
178+ t . test ( 'Index filter' , ( st ) => {
179+ const ast = u ( 'root' , [
180180 u ( 'node' , { word : 'foo' } ) ,
181181 u ( 'node' , { word : 'bar' } ) ,
182182 u ( 'skip' , { word : 'foo' } ) ,
183183 u ( 'skip' , { word : 'bar' } )
184184 ] )
185185
186- st . test ( 'type test' , function ( sst ) {
187- var index = new Index ( 'word' , ast , 'node' )
186+ st . test ( 'type test' , ( sst ) => {
187+ const index = new Index ( 'word' , ast , 'node' )
188188 sst . deepEqual ( index . get ( 'foo' ) , [ select ( 'node[word="foo"]' , ast ) ] )
189189 sst . deepEqual ( index . get ( 'bar' ) , [ select ( 'node[word="bar"]' , ast ) ] )
190190 sst . end ( )
191191 } )
192192
193- st . test ( 'function test' , function ( sst ) {
194- var index = new Index ( 'word' , ast , filter )
193+ st . test ( 'function test' , ( sst ) => {
194+ const index = new Index ( 'word' , ast , filter )
195195 sst . deepEqual ( index . get ( 'foo' ) , [ select ( 'node[word="foo"]' , ast ) ] )
196196 sst . deepEqual ( index . get ( 'bar' ) , [ select ( 'node[word="bar"]' , ast ) ] )
197197 sst . end ( )
@@ -209,19 +209,19 @@ test('index.get', function (t) {
209209 st . end ( )
210210 } )
211211
212- t . test ( 'computed keys' , function ( st ) {
212+ t . test ( 'computed keys' , ( st ) => {
213213 /**
214214 * @typedef {{x: number, y: number, z: number} } FunkyNode
215215 */
216216
217- var ast = u ( 'root' , { x : 0 , y : 4 , id : 0 } , [
217+ const ast = u ( 'root' , { x : 0 , y : 4 , id : 0 } , [
218218 u ( 'node' , { x : 3 , y : 2 , id : 1 } ) ,
219219 u ( 'node' , { x : 2 , y : 2 , id : 2 } ) ,
220220 u ( 'node' , { x : 3 , y : 1 , id : 3 } ) ,
221221 u ( 'node' , { x : 4 , y : 1 , id : 4 } )
222222 ] )
223223 // @ts -ignore it’s fine
224- var index = new Index ( xPlusY , ast )
224+ const index = new Index ( xPlusY , ast )
225225 st . deepEqual ( index . get ( 4 ) , [
226226 select ( '[id=0]' , ast ) ,
227227 select ( '[id=2]' , ast ) ,
@@ -249,20 +249,20 @@ test('index.get', function (t) {
249249 t . end ( )
250250} )
251251
252- test ( 'index.remove' , function ( t ) {
253- var ast = u ( 'root' , [
252+ test ( 'index.remove' , ( t ) => {
253+ const ast = u ( 'root' , [
254254 u ( 'bad' , { word : 'foo' } ) ,
255255 u ( 'node' , { word : 'foo' } ) ,
256256 u ( 'node' , { word : 'bar' } )
257257 ] )
258258
259- var index = new Index ( 'word' , ast )
259+ const index = new Index ( 'word' , ast )
260260 t . deepEqual ( index . get ( 'foo' ) , [
261261 select ( 'bad[word=foo]' , ast ) ,
262262 select ( 'node[word=foo]' , ast )
263263 ] )
264264
265- var result = index . remove ( select ( 'bad' , ast ) )
265+ const result = index . remove ( select ( 'bad' , ast ) )
266266 t . deepEqual ( index . get ( 'foo' ) , [ select ( 'node[word=foo]' , ast ) ] )
267267
268268 t . equal ( result , index , 'returns this' )
0 commit comments