Clarified error message; extended error to identifier end

Lengthening the reported error length to include all of the identifier necessitates scanning for all of the identifier. I also reset the `pos` after so other identifier scanning still happens.
This commit is contained in:
Josh Goldberg
2018-12-06 11:17:06 -08:00
parent 31fca3af4d
commit a211184347
13 changed files with 241 additions and 50 deletions
+1 -1
View File
@@ -1011,7 +1011,7 @@
"category": "Message",
"code": 1350
},
"An identifier cannot follow a numeric literal.": {
"An identifier or keyword cannot immediately follow a numeric literal.": {
"category": "Error",
"code": 1351
},
+7 -2
View File
@@ -991,9 +991,14 @@ namespace ts {
}
function checkForIdentifierStartAfterNumericLiteral() {
if (isIdentifierStart(text.charCodeAt(pos), languageVersion)) {
error(Diagnostics.An_identifier_cannot_follow_a_numeric_literal, pos, 1);
if (!isIdentifierStart(text.charCodeAt(pos), languageVersion)) {
return;
}
const identifierStart = pos;
const { length } = scanIdentifierParts();
error(Diagnostics.An_identifier_or_keyword_cannot_immediately_follow_a_numeric_literal, identifierStart, length);
pos = identifierStart;
}
function scanOctalDigits(): number {
@@ -1,65 +1,135 @@
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(1,16): error TS1351: An identifier cannot follow a numeric literal.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(3,2): error TS1351: An identifier cannot follow a numeric literal.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(1,16): error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(3,2): error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(3,2): error TS2304: Cannot find name 'a'.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(4,3): error TS1124: Digit expected.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(4,4): error TS2538: Type 'null' cannot be used as an index type.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(5,2): error TS1351: An identifier cannot follow a numeric literal.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(6,3): error TS1124: Digit expected.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(6,3): error TS2304: Cannot find name 'n'.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(7,2): error TS1351: An identifier cannot follow a numeric literal.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(7,2): error TS2304: Cannot find name 'a'.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(8,3): error TS1124: Digit expected.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(10,3): error TS1124: Digit expected.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(10,3): error TS2304: Cannot find name 'e'.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(12,3): error TS1005: ';' expected.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(13,3): error TS1351: An identifier cannot follow a numeric literal.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(13,3): error TS2304: Cannot find name 'a'.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(4,4): error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(4,4): error TS2304: Cannot find name 'a'.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(5,3): error TS1124: Digit expected.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(5,4): error TS2538: Type 'null' cannot be used as an index type.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(6,5): error TS1124: Digit expected.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(6,6): error TS2538: Type 'null' cannot be used as an index type.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(7,2): error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(8,4): error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(9,3): error TS1124: Digit expected.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(9,3): error TS2304: Cannot find name 'n'.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(10,5): error TS1124: Digit expected.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(10,5): error TS2304: Cannot find name 'n'.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(11,2): error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(11,2): error TS2304: Cannot find name 'a'.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(12,4): error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(12,4): error TS2304: Cannot find name 'a'.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(13,4): error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(13,4): error TS2304: Cannot find name 'abc'.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(14,3): error TS1124: Digit expected.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(15,5): error TS1124: Digit expected.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(18,3): error TS1124: Digit expected.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(18,3): error TS2304: Cannot find name 'e'.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(19,5): error TS1124: Digit expected.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(19,5): error TS2304: Cannot find name 'e'.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(22,3): error TS1005: ';' expected.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(23,5): error TS1005: ';' expected.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(24,3): error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(24,3): error TS2304: Cannot find name 'a'.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(25,5): error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(25,5): error TS2304: Cannot find name 'a'.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(26,5): error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
tests/cases/compiler/identifierStartAfterNumericLiteral.ts(26,5): error TS2304: Cannot find name 'abc'.
==== tests/cases/compiler/identifierStartAfterNumericLiteral.ts (16 errors) ====
==== tests/cases/compiler/identifierStartAfterNumericLiteral.ts (35 errors) ====
let valueIn = 3in[null];
~
!!! error TS1351: An identifier cannot follow a numeric literal.
~~
!!! error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
3a[null]
~
!!! error TS1351: An identifier cannot follow a numeric literal.
!!! error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
~
!!! error TS2304: Cannot find name 'a'.
123a[null]
~
!!! error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
~
!!! error TS2304: Cannot find name 'a'.
3e[null]
!!! error TS1124: Digit expected.
~~~~
!!! error TS2538: Type 'null' cannot be used as an index type.
123e[null]
!!! error TS1124: Digit expected.
~~~~
!!! error TS2538: Type 'null' cannot be used as an index type.
3in[null]
~
!!! error TS1351: An identifier cannot follow a numeric literal.
~~
!!! error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
123in[null]
~~
!!! error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
3en[null]
!!! error TS1124: Digit expected.
~
!!! error TS2304: Cannot find name 'n'.
123en[null]
!!! error TS1124: Digit expected.
~
!!! error TS2304: Cannot find name 'n'.
1a
~
!!! error TS1351: An identifier cannot follow a numeric literal.
!!! error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
~
!!! error TS2304: Cannot find name 'a'.
123a
~
!!! error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
~
!!! error TS2304: Cannot find name 'a'.
123abc
~~~
!!! error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
~~~
!!! error TS2304: Cannot find name 'abc'.
1e
!!! error TS1124: Digit expected.
123e
!!! error TS1124: Digit expected.
1e9
123e9
1ee
!!! error TS1124: Digit expected.
~
!!! error TS2304: Cannot find name 'e'.
123ee
!!! error TS1124: Digit expected.
~
!!! error TS2304: Cannot find name 'e'.
1n
123n
2n2
~
!!! error TS1005: ';' expected.
123n2
~
!!! error TS1005: ';' expected.
2na
~
!!! error TS1351: An identifier cannot follow a numeric literal.
!!! error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
~
!!! error TS2304: Cannot find name 'a'.
123na
~
!!! error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
~
!!! error TS2304: Cannot find name 'a'.
123nabc
~~~
!!! error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
~~~
!!! error TS2304: Cannot find name 'abc'.
@@ -2,34 +2,68 @@
let valueIn = 3in[null];
3a[null]
123a[null]
3e[null]
123e[null]
3in[null]
123in[null]
3en[null]
123en[null]
1a
123a
123abc
1e
123e
1e9
123e9
1ee
123ee
1n
123n
2n2
123n2
2na
123na
123nabc
//// [identifierStartAfterNumericLiteral.js]
var valueIn = 3 in [null];
3;
a[null];
123;
a[null];
3e[null];
123e[null];
3 in [null];
123 in [null];
3e;
n[null];
123e;
n[null];
1;
a;
123;
a;
123;
abc;
1e;
123e;
1e9;
123e9;
1e;
e;
123e;
e;
1n;
123n;
2n;
2;
123n;
2;
2n;
a;
123n;
a;
123n;
abc;
@@ -3,14 +3,27 @@ let valueIn = 3in[null];
>valueIn : Symbol(valueIn, Decl(identifierStartAfterNumericLiteral.ts, 0, 3))
3a[null]
123a[null]
3e[null]
123e[null]
3in[null]
123in[null]
3en[null]
123en[null]
1a
123a
123abc
1e
123e
1e9
123e9
1ee
123ee
1n
123n
2n2
123n2
2na
123na
123nabc
@@ -12,45 +12,101 @@ let valueIn = 3in[null];
>a : any
>null : null
123a[null]
>123 : 123
>a[null] : any
>a : any
>null : null
3e[null]
>3e[null] : any
>3e : 3
>null : null
123e[null]
>123e[null] : any
>123e : 123
>null : null
3in[null]
>3in[null] : boolean
>3 : 3
>[null] : null[]
>null : null
123in[null]
>123in[null] : boolean
>123 : 123
>[null] : null[]
>null : null
3en[null]
>3e : 3
>n[null] : any
>n : any
>null : null
123en[null]
>123e : 123
>n[null] : any
>n : any
>null : null
1a
>1 : 1
>a : any
123a
>123 : 123
>a : any
123abc
>123 : 123
>abc : any
1e
>1e : 1
123e
>123e : 123
1e9
>1e9 : 1000000000
123e9
>123e9 : 123000000000
1ee
>1e : 1
>e : any
123ee
>123e : 123
>e : any
1n
>1n : 1n
123n
>123n : 123n
2n2
>2n : 2n
>2 : 2
123n2
>123n : 123n
>2 : 2
2na
>2n : 2n
>a : any
123na
>123n : 123n
>a : any
123nabc
>123n : 123n
>abc : any
@@ -1,5 +1,5 @@
tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts(3,3): error TS1351: An identifier cannot follow a numeric literal.
tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts(9,15): error TS1351: An identifier cannot follow a numeric literal.
tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts(3,3): error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts(9,15): error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts(9,23): error TS1005: ',' expected.
tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts(9,24): error TS1109: Expression expected.
@@ -8,16 +8,16 @@ tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts(9,24): error
1..toString();
1.0.toString();
1.toString();
~
!!! error TS1351: An identifier cannot follow a numeric literal.
~~~~~~~~
!!! error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
1.+2.0 + 3. ;
// Preserve whitespace where important for JS compatibility
var i: number = 1;
var test1 = i.toString();
var test2 = 2.toString();
~
!!! error TS1351: An identifier cannot follow a numeric literal.
~~~~~~~~
!!! error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
~
!!! error TS1005: ',' expected.
~
@@ -1,9 +1,9 @@
tests/cases/compiler/parseBigInt.ts(51,20): error TS2736: Operator '+' cannot be applied to type '123n'.
tests/cases/compiler/parseBigInt.ts(52,23): error TS2736: Operator '+' cannot be applied to type '291n'.
tests/cases/compiler/parseBigInt.ts(56,25): error TS1005: ',' expected.
tests/cases/compiler/parseBigInt.ts(57,25): error TS1351: An identifier cannot follow a numeric literal.
tests/cases/compiler/parseBigInt.ts(58,22): error TS1351: An identifier cannot follow a numeric literal.
tests/cases/compiler/parseBigInt.ts(59,28): error TS1351: An identifier cannot follow a numeric literal.
tests/cases/compiler/parseBigInt.ts(57,25): error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
tests/cases/compiler/parseBigInt.ts(58,22): error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
tests/cases/compiler/parseBigInt.ts(59,28): error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
tests/cases/compiler/parseBigInt.ts(60,23): error TS1177: Binary digit expected.
tests/cases/compiler/parseBigInt.ts(61,20): error TS1178: Octal digit expected.
tests/cases/compiler/parseBigInt.ts(62,20): error TS1125: Hexadecimal digit expected.
@@ -82,13 +82,13 @@ tests/cases/compiler/parseBigInt.ts(70,72): error TS2345: Argument of type '3' i
!!! error TS1005: ',' expected.
{ const scientific = 1e2n; }
~
!!! error TS1351: An identifier cannot follow a numeric literal.
!!! error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
{ const decimal = 4.1n; }
~
!!! error TS1351: An identifier cannot follow a numeric literal.
!!! error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
{ const leadingDecimal = .1n; }
~
!!! error TS1351: An identifier cannot follow a numeric literal.
!!! error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
const emptyBinary = 0bn; // should error but infer 0n
!!! error TS1177: Binary digit expected.
@@ -1,7 +1,7 @@
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/1.ts(1,5): error TS6188: Numeric separators are not allowed here.
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/2.ts(1,3): error TS6188: Numeric separators are not allowed here.
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/3.ts(1,2): error TS6188: Numeric separators are not allowed here.
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/3.ts(1,3): error TS1351: An identifier cannot follow a numeric literal.
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/3.ts(1,3): error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/3.ts(1,3): error TS2304: Cannot find name 'B0101'.
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/4.ts(1,6): error TS6189: Multiple consecutive numeric separators are not permitted.
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/5.ts(1,13): error TS6189: Multiple consecutive numeric separators are not permitted.
@@ -24,8 +24,8 @@ tests/cases/conformance/parser/ecmascriptnext/numericSeparators/6.ts(1,5): error
0_B0101
~
!!! error TS6188: Numeric separators are not allowed here.
~
!!! error TS1351: An identifier cannot follow a numeric literal.
~~~~~
!!! error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
~~~~~
!!! error TS2304: Cannot find name 'B0101'.
@@ -1,7 +1,7 @@
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/1.ts(1,5): error TS6188: Numeric separators are not allowed here.
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/2.ts(1,3): error TS6188: Numeric separators are not allowed here.
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/3.ts(1,2): error TS6188: Numeric separators are not allowed here.
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/3.ts(1,3): error TS1351: An identifier cannot follow a numeric literal.
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/3.ts(1,3): error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/3.ts(1,3): error TS2304: Cannot find name 'X0101'.
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/4.ts(1,6): error TS6189: Multiple consecutive numeric separators are not permitted.
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/5.ts(1,13): error TS6189: Multiple consecutive numeric separators are not permitted.
@@ -24,8 +24,8 @@ tests/cases/conformance/parser/ecmascriptnext/numericSeparators/6.ts(1,5): error
0_X0101
~
!!! error TS6188: Numeric separators are not allowed here.
~
!!! error TS1351: An identifier cannot follow a numeric literal.
~~~~~
!!! error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
~~~~~
!!! error TS2304: Cannot find name 'X0101'.
@@ -1,7 +1,7 @@
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/1.ts(1,5): error TS6188: Numeric separators are not allowed here.
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/2.ts(1,3): error TS6188: Numeric separators are not allowed here.
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/3.ts(1,2): error TS6188: Numeric separators are not allowed here.
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/3.ts(1,3): error TS1351: An identifier cannot follow a numeric literal.
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/3.ts(1,3): error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/3.ts(1,3): error TS2304: Cannot find name 'O0101'.
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/4.ts(1,6): error TS6189: Multiple consecutive numeric separators are not permitted.
tests/cases/conformance/parser/ecmascriptnext/numericSeparators/5.ts(1,13): error TS6189: Multiple consecutive numeric separators are not permitted.
@@ -24,8 +24,8 @@ tests/cases/conformance/parser/ecmascriptnext/numericSeparators/6.ts(1,5): error
0_O0101
~
!!! error TS6188: Numeric separators are not allowed here.
~
!!! error TS1351: An identifier cannot follow a numeric literal.
~~~~~
!!! error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
~~~~~
!!! error TS2304: Cannot find name 'O0101'.
@@ -1,6 +1,6 @@
tests/cases/conformance/jsx/file.tsx(10,8): error TS1003: Identifier expected.
tests/cases/conformance/jsx/file.tsx(10,10): error TS1351: An identifier cannot follow a numeric literal.
tests/cases/conformance/jsx/file.tsx(10,10): error TS1005: ';' expected.
tests/cases/conformance/jsx/file.tsx(10,10): error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
tests/cases/conformance/jsx/file.tsx(10,10): error TS2304: Cannot find name 'data'.
tests/cases/conformance/jsx/file.tsx(10,15): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
tests/cases/conformance/jsx/file.tsx(10,18): error TS1005: ':' expected.
@@ -26,11 +26,11 @@ tests/cases/conformance/jsx/file.tsx(11,20): error TS1161: Unterminated regular
<test1 32data={32} />;
~~
!!! error TS1003: Identifier expected.
~
!!! error TS1351: An identifier cannot follow a numeric literal.
~~~~
!!! error TS1005: ';' expected.
~~~~
!!! error TS1351: An identifier or keyword cannot immediately follow a numeric literal.
~~~~
!!! error TS2304: Cannot find name 'data'.
~~~~
!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
@@ -1,13 +1,26 @@
let valueIn = 3in[null];
3a[null]
123a[null]
3e[null]
123e[null]
3in[null]
123in[null]
3en[null]
123en[null]
1a
123a
123abc
1e
123e
1e9
123e9
1ee
123ee
1n
123n
2n2
123n2
2na
123na
123nabc