File tree 2 files changed +25
-7
lines changed
2 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -852,7 +852,8 @@ describe('Lexer', () => {
852
852
} ) ;
853
853
854
854
expectSyntaxError ( '.123' ) . to . deep . equal ( {
855
- message : 'Syntax Error: Unexpected character: ".".' ,
855
+ message :
856
+ 'Syntax Error: Invalid number, expected digit before ".", did you mean "0.123"?' ,
856
857
locations : [ { line : 1 , column : 1 } ] ,
857
858
} ) ;
858
859
@@ -1030,7 +1031,7 @@ describe('Lexer', () => {
1030
1031
1031
1032
it ( 'lex reports useful unknown character error' , ( ) => {
1032
1033
expectSyntaxError ( '..' ) . to . deep . equal ( {
1033
- message : 'Syntax Error: Unexpected character: ".". ' ,
1034
+ message : 'Syntax Error: Unexpected "..", did you mean "..."? ' ,
1034
1035
locations : [ { line : 1 , column : 1 } ] ,
1035
1036
} ) ;
1036
1037
Original file line number Diff line number Diff line change @@ -258,14 +258,31 @@ function readNextToken(lexer: Lexer, start: number): Token {
258
258
return createToken ( lexer , TokenKind . PAREN_L , position , position + 1 ) ;
259
259
case 0x0029 : // )
260
260
return createToken ( lexer , TokenKind . PAREN_R , position , position + 1 ) ;
261
- case 0x002e : // .
262
- if (
263
- body . charCodeAt ( position + 1 ) === 0x002e &&
264
- body . charCodeAt ( position + 2 ) === 0x002e
265
- ) {
261
+ case 0x002e : {
262
+ // .
263
+ const nextCode = body . charCodeAt ( position + 1 ) ;
264
+ if ( nextCode === 0x002e && body . charCodeAt ( position + 2 ) === 0x002e ) {
266
265
return createToken ( lexer , TokenKind . SPREAD , position , position + 3 ) ;
267
266
}
267
+ if ( nextCode === 0x002e ) {
268
+ throw syntaxError (
269
+ lexer . source ,
270
+ position ,
271
+ 'Unexpected "..", did you mean "..."?' ,
272
+ ) ;
273
+ } else if ( isDigit ( nextCode ) ) {
274
+ const digits = lexer . source . body . slice (
275
+ position + 1 ,
276
+ readDigits ( lexer , position + 1 , nextCode ) ,
277
+ ) ;
278
+ throw syntaxError (
279
+ lexer . source ,
280
+ position ,
281
+ `Invalid number, expected digit before ".", did you mean "0.${ digits } "?` ,
282
+ ) ;
283
+ }
268
284
break ;
285
+ }
269
286
case 0x003a : // :
270
287
return createToken ( lexer , TokenKind . COLON , position , position + 1 ) ;
271
288
case 0x003d : // =
You can’t perform that action at this time.
0 commit comments