File tree Expand file tree Collapse file tree 2 files changed +25
-7
lines changed Expand file tree Collapse file tree 2 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -852,7 +852,8 @@ describe('Lexer', () => {
852852 } ) ;
853853
854854 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"?' ,
856857 locations : [ { line : 1 , column : 1 } ] ,
857858 } ) ;
858859
@@ -1030,7 +1031,7 @@ describe('Lexer', () => {
10301031
10311032 it ( 'lex reports useful unknown character error' , ( ) => {
10321033 expectSyntaxError ( '..' ) . to . deep . equal ( {
1033- message : 'Syntax Error: Unexpected character: ".". ' ,
1034+ message : 'Syntax Error: Unexpected "..", did you mean "..."? ' ,
10341035 locations : [ { line : 1 , column : 1 } ] ,
10351036 } ) ;
10361037
Original file line number Diff line number Diff line change @@ -258,14 +258,31 @@ function readNextToken(lexer: Lexer, start: number): Token {
258258 return createToken ( lexer , TokenKind . PAREN_L , position , position + 1 ) ;
259259 case 0x0029 : // )
260260 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 ) {
266265 return createToken ( lexer , TokenKind . SPREAD , position , position + 3 ) ;
267266 }
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+ }
268284 break ;
285+ }
269286 case 0x003a : // :
270287 return createToken ( lexer , TokenKind . COLON , position , position + 1 ) ;
271288 case 0x003d : // =
You can’t perform that action at this time.
0 commit comments