@@ -29,12 +29,12 @@ function expectSyntaxError(text: string) {
29
29
describe ( 'Lexer' , ( ) => {
30
30
it ( 'disallows uncommon control characters' , ( ) => {
31
31
expectSyntaxError ( '\u0007' ) . to . deep . equal ( {
32
- message : 'Syntax Error: Cannot contain the invalid character "\\u0007" .' ,
32
+ message : 'Syntax Error: Invalid character: U+0007 .' ,
33
33
locations : [ { line : 1 , column : 1 } ] ,
34
34
} ) ;
35
35
} ) ;
36
36
37
- it ( 'accepts BOM header' , ( ) => {
37
+ it ( 'ignores BOM header' , ( ) => {
38
38
expect ( lexOne ( '\uFEFF foo' ) ) . to . contain ( {
39
39
kind : TokenKind . NAME ,
40
40
start : 2 ,
@@ -138,6 +138,13 @@ describe('Lexer', () => {
138
138
value : 'foo' ,
139
139
} ) ;
140
140
141
+ expect ( lexOne ( '\t\tfoo\t\t' ) ) . to . contain ( {
142
+ kind : TokenKind . NAME ,
143
+ start : 2 ,
144
+ end : 5 ,
145
+ value : 'foo' ,
146
+ } ) ;
147
+
141
148
expect (
142
149
lexOne ( `
143
150
#comment
@@ -166,7 +173,7 @@ describe('Lexer', () => {
166
173
caughtError = error ;
167
174
}
168
175
expect ( String ( caughtError ) ) . to . equal ( dedent `
169
- Syntax Error: Cannot parse the unexpected character "?".
176
+ Syntax Error: Unexpected character: "?".
170
177
171
178
GraphQL request:3:5
172
179
2 |
@@ -186,7 +193,7 @@ describe('Lexer', () => {
186
193
caughtError = error ;
187
194
}
188
195
expect ( String ( caughtError ) ) . to . equal ( dedent `
189
- Syntax Error: Cannot parse the unexpected character "?".
196
+ Syntax Error: Unexpected character: "?".
190
197
191
198
foo.js:13:6
192
199
12 |
@@ -205,7 +212,7 @@ describe('Lexer', () => {
205
212
caughtError = error ;
206
213
}
207
214
expect ( String ( caughtError ) ) . to . equal ( dedent `
208
- Syntax Error: Cannot parse the unexpected character "?".
215
+ Syntax Error: Unexpected character: "?".
209
216
210
217
foo.js:1:5
211
218
1 | ?
@@ -293,13 +300,13 @@ describe('Lexer', () => {
293
300
294
301
expectSyntaxError ( '"contains unescaped \u0007 control char"' ) . to . deep . equal (
295
302
{
296
- message : 'Syntax Error: Invalid character within String: "\\u0007" .' ,
303
+ message : 'Syntax Error: Invalid character within String: U+0007 .' ,
297
304
locations : [ { line : 1 , column : 21 } ] ,
298
305
} ,
299
306
) ;
300
307
301
308
expectSyntaxError ( '"null-byte is not \u0000 end of file"' ) . to . deep . equal ( {
302
- message : 'Syntax Error: Invalid character within String: "\\u0000" .' ,
309
+ message : 'Syntax Error: Invalid character within String: U+0000 .' ,
303
310
locations : [ { line : 1 , column : 19 } ] ,
304
311
} ) ;
305
312
@@ -314,38 +321,38 @@ describe('Lexer', () => {
314
321
} ) ;
315
322
316
323
expectSyntaxError ( '"bad \\z esc"' ) . to . deep . equal ( {
317
- message : 'Syntax Error: Invalid character escape sequence: \\z.' ,
318
- locations : [ { line : 1 , column : 7 } ] ,
324
+ message : 'Syntax Error: Invalid character escape sequence: " \\z" .' ,
325
+ locations : [ { line : 1 , column : 6 } ] ,
319
326
} ) ;
320
327
321
328
expectSyntaxError ( '"bad \\x esc"' ) . to . deep . equal ( {
322
- message : 'Syntax Error: Invalid character escape sequence: \\x.' ,
323
- locations : [ { line : 1 , column : 7 } ] ,
329
+ message : 'Syntax Error: Invalid character escape sequence: " \\x" .' ,
330
+ locations : [ { line : 1 , column : 6 } ] ,
324
331
} ) ;
325
332
326
333
expectSyntaxError ( '"bad \\u1 esc"' ) . to . deep . equal ( {
327
- message : 'Syntax Error: Invalid character escape sequence: \\u1 es.' ,
328
- locations : [ { line : 1 , column : 7 } ] ,
334
+ message : 'Syntax Error: Invalid Unicode escape sequence: " \\u1 es" .' ,
335
+ locations : [ { line : 1 , column : 6 } ] ,
329
336
} ) ;
330
337
331
338
expectSyntaxError ( '"bad \\u0XX1 esc"' ) . to . deep . equal ( {
332
- message : 'Syntax Error: Invalid character escape sequence: \\u0XX1.' ,
333
- locations : [ { line : 1 , column : 7 } ] ,
339
+ message : 'Syntax Error: Invalid Unicode escape sequence: " \\u0XX1" .' ,
340
+ locations : [ { line : 1 , column : 6 } ] ,
334
341
} ) ;
335
342
336
343
expectSyntaxError ( '"bad \\uXXXX esc"' ) . to . deep . equal ( {
337
- message : 'Syntax Error: Invalid character escape sequence: \\uXXXX.' ,
338
- locations : [ { line : 1 , column : 7 } ] ,
344
+ message : 'Syntax Error: Invalid Unicode escape sequence: " \\uXXXX" .' ,
345
+ locations : [ { line : 1 , column : 6 } ] ,
339
346
} ) ;
340
347
341
348
expectSyntaxError ( '"bad \\uFXXX esc"' ) . to . deep . equal ( {
342
- message : 'Syntax Error: Invalid character escape sequence: \\uFXXX.' ,
343
- locations : [ { line : 1 , column : 7 } ] ,
349
+ message : 'Syntax Error: Invalid Unicode escape sequence: " \\uFXXX" .' ,
350
+ locations : [ { line : 1 , column : 6 } ] ,
344
351
} ) ;
345
352
346
353
expectSyntaxError ( '"bad \\uXXXF esc"' ) . to . deep . equal ( {
347
- message : 'Syntax Error: Invalid character escape sequence: \\uXXXF.' ,
348
- locations : [ { line : 1 , column : 7 } ] ,
354
+ message : 'Syntax Error: Invalid Unicode escape sequence: " \\uXXXF" .' ,
355
+ locations : [ { line : 1 , column : 6 } ] ,
349
356
} ) ;
350
357
} ) ;
351
358
@@ -481,14 +488,14 @@ describe('Lexer', () => {
481
488
expectSyntaxError (
482
489
'"""contains unescaped \u0007 control char"""' ,
483
490
) . to . deep . equal ( {
484
- message : 'Syntax Error: Invalid character within String: "\\u0007" .' ,
491
+ message : 'Syntax Error: Invalid character within String: U+0007 .' ,
485
492
locations : [ { line : 1 , column : 23 } ] ,
486
493
} ) ;
487
494
488
495
expectSyntaxError (
489
496
'"""null-byte is not \u0000 end of file"""' ,
490
497
) . to . deep . equal ( {
491
- message : 'Syntax Error: Invalid character within String: "\\u0000" .' ,
498
+ message : 'Syntax Error: Invalid character within String: U+0000 .' ,
492
499
locations : [ { line : 1 , column : 21 } ] ,
493
500
} ) ;
494
501
} ) ;
@@ -624,7 +631,7 @@ describe('Lexer', () => {
624
631
} ) ;
625
632
626
633
expectSyntaxError ( '+1' ) . to . deep . equal ( {
627
- message : 'Syntax Error: Cannot parse the unexpected character "+".' ,
634
+ message : 'Syntax Error: Unexpected character: "+".' ,
628
635
locations : [ { line : 1 , column : 1 } ] ,
629
636
} ) ;
630
637
@@ -649,7 +656,7 @@ describe('Lexer', () => {
649
656
} ) ;
650
657
651
658
expectSyntaxError ( '.123' ) . to . deep . equal ( {
652
- message : 'Syntax Error: Cannot parse the unexpected character ".".' ,
659
+ message : 'Syntax Error: Unexpected character: ".".' ,
653
660
locations : [ { line : 1 , column : 1 } ] ,
654
661
} ) ;
655
662
@@ -673,6 +680,11 @@ describe('Lexer', () => {
673
680
locations : [ { line : 1 , column : 5 } ] ,
674
681
} ) ;
675
682
683
+ expectSyntaxError ( '1.0e"' ) . to . deep . equal ( {
684
+ message : "Syntax Error: Invalid number, expected digit but got: '\"'." ,
685
+ locations : [ { line : 1 , column : 5 } ] ,
686
+ } ) ;
687
+
676
688
expectSyntaxError ( '1.2e3e' ) . to . deep . equal ( {
677
689
message : 'Syntax Error: Invalid number, expected digit but got: "e".' ,
678
690
locations : [ { line : 1 , column : 6 } ] ,
@@ -707,7 +719,7 @@ describe('Lexer', () => {
707
719
locations : [ { line : 1 , column : 2 } ] ,
708
720
} ) ;
709
721
expectSyntaxError ( '1\u00DF' ) . to . deep . equal ( {
710
- message : 'Syntax Error: Cannot parse the unexpected character "\\u00DF" .' ,
722
+ message : 'Syntax Error: Unexpected character: U+00DF .' ,
711
723
locations : [ { line : 1 , column : 2 } ] ,
712
724
} ) ;
713
725
expectSyntaxError ( '1.23f' ) . to . deep . equal ( {
@@ -815,22 +827,17 @@ describe('Lexer', () => {
815
827
816
828
it ( 'lex reports useful unknown character error' , ( ) => {
817
829
expectSyntaxError ( '..' ) . to . deep . equal ( {
818
- message : 'Syntax Error: Cannot parse the unexpected character ".".' ,
830
+ message : 'Syntax Error: Unexpected character: ".".' ,
819
831
locations : [ { line : 1 , column : 1 } ] ,
820
832
} ) ;
821
833
822
834
expectSyntaxError ( '?' ) . to . deep . equal ( {
823
- message : 'Syntax Error: Cannot parse the unexpected character "?".' ,
835
+ message : 'Syntax Error: Unexpected character: "?".' ,
824
836
locations : [ { line : 1 , column : 1 } ] ,
825
837
} ) ;
826
838
827
839
expectSyntaxError ( '\u203B' ) . to . deep . equal ( {
828
- message : 'Syntax Error: Cannot parse the unexpected character "\\u203B".' ,
829
- locations : [ { line : 1 , column : 1 } ] ,
830
- } ) ;
831
-
832
- expectSyntaxError ( '\u200b' ) . to . deep . equal ( {
833
- message : 'Syntax Error: Cannot parse the unexpected character "\\u200B".' ,
840
+ message : 'Syntax Error: Unexpected character: U+203B.' ,
834
841
locations : [ { line : 1 , column : 1 } ] ,
835
842
} ) ;
836
843
} ) ;
@@ -893,6 +900,31 @@ describe('Lexer', () => {
893
900
TokenKind . EOF ,
894
901
] ) ;
895
902
} ) ;
903
+
904
+ it ( 'lexes comments' , ( ) => {
905
+ expect ( lexOne ( '# Comment' ) . prev ) . to . contain ( {
906
+ kind : TokenKind . COMMENT ,
907
+ start : 0 ,
908
+ end : 9 ,
909
+ value : ' Comment' ,
910
+ } ) ;
911
+ expect ( lexOne ( '# Comment\nAnother line' ) . prev ) . to . contain ( {
912
+ kind : TokenKind . COMMENT ,
913
+ start : 0 ,
914
+ end : 9 ,
915
+ value : ' Comment' ,
916
+ } ) ;
917
+ expect ( lexOne ( '# Comment\r\nAnother line' ) . prev ) . to . contain ( {
918
+ kind : TokenKind . COMMENT ,
919
+ start : 0 ,
920
+ end : 9 ,
921
+ value : ' Comment' ,
922
+ } ) ;
923
+ expectSyntaxError ( '# \u0007' ) . to . deep . equal ( {
924
+ message : 'Syntax Error: Invalid character: U+0007.' ,
925
+ locations : [ { line : 1 , column : 3 } ] ,
926
+ } ) ;
927
+ } ) ;
896
928
} ) ;
897
929
898
930
describe ( 'isPunctuatorTokenKind' , ( ) => {
0 commit comments