@@ -3,7 +3,7 @@ import { describe, it } from 'mocha';
3
3
4
4
import { kitchenSinkQuery } from '../../__testUtils__/kitchenSinkQuery' ;
5
5
6
- import type { ASTNode } from '../ast' ;
6
+ import type { ASTNode , SelectionSetNode } from '../ast' ;
7
7
import { isNode } from '../ast' ;
8
8
import { Kind } from '../kinds' ;
9
9
import { parse } from '../parser' ;
@@ -51,8 +51,7 @@ function checkVisitorFnArgs(ast: any, args: any, isEdited: boolean = false) {
51
51
}
52
52
53
53
function getValue ( node : ASTNode ) {
54
- // @ts -expect-error FIXME: TS Conversion
55
- return node . value != null ? node . value : undefined ;
54
+ return 'value' in node ? node . value : undefined ;
56
55
}
57
56
58
57
describe ( 'Visitor' , ( ) => {
@@ -62,7 +61,7 @@ describe('Visitor', () => {
62
61
} ) ;
63
62
64
63
it ( 'validates path argument' , ( ) => {
65
- const visited = [ ] ;
64
+ const visited : Array < any > = [ ] ;
66
65
67
66
const ast = parse ( '{ a }' , { noLocation : true } ) ;
68
67
@@ -93,7 +92,7 @@ describe('Visitor', () => {
93
92
94
93
it ( 'validates ancestors argument' , ( ) => {
95
94
const ast = parse ( '{ a }' , { noLocation : true } ) ;
96
- const visitedNodes = [ ] ;
95
+ const visitedNodes : Array < any > = [ ] ;
97
96
98
97
visit ( ast , {
99
98
enter ( node , key , parent , _path , ancestors ) {
@@ -122,7 +121,7 @@ describe('Visitor', () => {
122
121
it ( 'allows editing a node both on enter and on leave' , ( ) => {
123
122
const ast = parse ( '{ a, b, c { a, b, c } }' , { noLocation : true } ) ;
124
123
125
- let selectionSet ;
124
+ let selectionSet : SelectionSetNode ;
126
125
127
126
const editedAST = visit ( ast , {
128
127
OperationDefinition : {
@@ -265,8 +264,7 @@ describe('Visitor', () => {
265
264
if ( node . kind === 'Field' && node . name . value === 'a' ) {
266
265
return {
267
266
kind : 'Field' ,
268
- // @ts -expect-error FIXME: TS Conversion
269
- selectionSet : [ addedField ] . concat ( node . selectionSet ) ,
267
+ selectionSet : [ addedField , node . selectionSet ] ,
270
268
} ;
271
269
}
272
270
if ( node === addedField ) {
@@ -279,7 +277,7 @@ describe('Visitor', () => {
279
277
} ) ;
280
278
281
279
it ( 'allows skipping a sub-tree' , ( ) => {
282
- const visited = [ ] ;
280
+ const visited : Array < any > = [ ] ;
283
281
284
282
const ast = parse ( '{ a, b { x }, c }' , { noLocation : true } ) ;
285
283
visit ( ast , {
@@ -317,7 +315,7 @@ describe('Visitor', () => {
317
315
} ) ;
318
316
319
317
it ( 'allows early exit while visiting' , ( ) => {
320
- const visited = [ ] ;
318
+ const visited : Array < any > = [ ] ;
321
319
322
320
const ast = parse ( '{ a, b { x }, c }' , { noLocation : true } ) ;
323
321
visit ( ast , {
@@ -352,7 +350,7 @@ describe('Visitor', () => {
352
350
} ) ;
353
351
354
352
it ( 'allows early exit while leaving' , ( ) => {
355
- const visited = [ ] ;
353
+ const visited : Array < any > = [ ] ;
356
354
357
355
const ast = parse ( '{ a, b { x }, c }' , { noLocation : true } ) ;
358
356
visit ( ast , {
@@ -389,7 +387,7 @@ describe('Visitor', () => {
389
387
} ) ;
390
388
391
389
it ( 'allows a named functions visitor API' , ( ) => {
392
- const visited = [ ] ;
390
+ const visited : Array < any > = [ ] ;
393
391
394
392
const ast = parse ( '{ a, b { x }, c }' , { noLocation : true } ) ;
395
393
visit ( ast , {
@@ -438,7 +436,7 @@ describe('Visitor', () => {
438
436
} ,
439
437
} ) ;
440
438
441
- const visited = [ ] ;
439
+ const visited : Array < any > = [ ] ;
442
440
visit ( customAST , {
443
441
enter ( node ) {
444
442
visited . push ( [ 'enter' , node . kind , getValue ( node ) ] ) ;
@@ -469,7 +467,7 @@ describe('Visitor', () => {
469
467
noLocation : true ,
470
468
allowLegacyFragmentVariables : true ,
471
469
} ) ;
472
- const visited = [ ] ;
470
+ const visited : Array < any > = [ ] ;
473
471
474
472
visit ( ast , {
475
473
enter ( node ) {
@@ -516,8 +514,8 @@ describe('Visitor', () => {
516
514
517
515
it ( 'visits kitchen sink' , ( ) => {
518
516
const ast = parse ( kitchenSinkQuery ) ;
519
- const visited = [ ] ;
520
- const argsStack = [ ] ;
517
+ const visited : Array < any > = [ ] ;
518
+ const argsStack : Array < any > = [ ] ;
521
519
522
520
visit ( ast , {
523
521
enter ( node , key , parent ) {
@@ -895,7 +893,7 @@ describe('Visitor', () => {
895
893
// Note: nearly identical to the above test of the same test but
896
894
// using visitInParallel.
897
895
it ( 'allows skipping a sub-tree' , ( ) => {
898
- const visited = [ ] ;
896
+ const visited : Array < any > = [ ] ;
899
897
900
898
const ast = parse ( '{ a, b { x }, c }' ) ;
901
899
visit (
@@ -938,7 +936,7 @@ describe('Visitor', () => {
938
936
} ) ;
939
937
940
938
it ( 'allows skipping different sub-trees' , ( ) => {
941
- const visited = [ ] ;
939
+ const visited : Array < any > = [ ] ;
942
940
943
941
const ast = parse ( '{ a { x }, b { y} }' ) ;
944
942
visit (
@@ -1014,7 +1012,7 @@ describe('Visitor', () => {
1014
1012
// Note: nearly identical to the above test of the same test but
1015
1013
// using visitInParallel.
1016
1014
it ( 'allows early exit while visiting' , ( ) => {
1017
- const visited = [ ] ;
1015
+ const visited : Array < any > = [ ] ;
1018
1016
1019
1017
const ast = parse ( '{ a, b { x }, c }' ) ;
1020
1018
visit (
@@ -1054,7 +1052,7 @@ describe('Visitor', () => {
1054
1052
} ) ;
1055
1053
1056
1054
it ( 'allows early exit from different points' , ( ) => {
1057
- const visited = [ ] ;
1055
+ const visited : Array < any > = [ ] ;
1058
1056
1059
1057
const ast = parse ( '{ a { y }, b { x } }' ) ;
1060
1058
visit (
@@ -1116,7 +1114,7 @@ describe('Visitor', () => {
1116
1114
// Note: nearly identical to the above test of the same test but
1117
1115
// using visitInParallel.
1118
1116
it ( 'allows early exit while leaving' , ( ) => {
1119
- const visited = [ ] ;
1117
+ const visited : Array < any > = [ ] ;
1120
1118
1121
1119
const ast = parse ( '{ a, b { x }, c }' ) ;
1122
1120
visit (
@@ -1157,7 +1155,7 @@ describe('Visitor', () => {
1157
1155
} ) ;
1158
1156
1159
1157
it ( 'allows early exit from leaving different points' , ( ) => {
1160
- const visited = [ ] ;
1158
+ const visited : Array < any > = [ ] ;
1161
1159
1162
1160
const ast = parse ( '{ a { y }, b { x } }' ) ;
1163
1161
visit (
@@ -1233,7 +1231,7 @@ describe('Visitor', () => {
1233
1231
} ) ;
1234
1232
1235
1233
it ( 'allows for editing on enter' , ( ) => {
1236
- const visited = [ ] ;
1234
+ const visited : Array < any > = [ ] ;
1237
1235
1238
1236
const ast = parse ( '{ a, b, c { a, b, c } }' , { noLocation : true } ) ;
1239
1237
const editedAST = visit (
@@ -1297,7 +1295,7 @@ describe('Visitor', () => {
1297
1295
} ) ;
1298
1296
1299
1297
it ( 'allows for editing on leave' , ( ) => {
1300
- const visited = [ ] ;
1298
+ const visited : Array < any > = [ ] ;
1301
1299
1302
1300
const ast = parse ( '{ a, b, c { a, b, c } }' , { noLocation : true } ) ;
1303
1301
const editedAST = visit (
0 commit comments