diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e3f8e1a7ad5..b7aaaf02742 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1011,6 +1011,10 @@ "category": "Message", "code": 1350 }, + "An identifier cannot follow a numeric literal.": { + "category": "Error", + "code": 1351 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 9eedfeefb53..3762eaa91fa 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -974,7 +974,10 @@ namespace ts { else { result = text.substring(start, end); // No need to use all the fragments; no _ removal needed } + + checkForIdentifierAfterNumericLiteral(); if (decimalFragment !== undefined || tokenFlags & TokenFlags.Scientific) { + checkForIdentifierAfterNumericLiteral(); return { type: SyntaxKind.NumericLiteral, value: "" + +result // if value is not an integer, it can be safely coerced to a number @@ -983,10 +986,17 @@ namespace ts { else { tokenValue = result; const type = checkBigIntSuffix(); // if value is an integer, check whether it is a bigint + checkForIdentifierAfterNumericLiteral(); return { type, value: tokenValue }; } } + function checkForIdentifierAfterNumericLiteral() { + if (isIdentifierStart(text.charCodeAt(pos), languageVersion)) { + error(Diagnostics.An_identifier_cannot_follow_a_numeric_literal, pos, 1); + } + } + function scanOctalDigits(): number { const start = pos; while (isOctalDigit(text.charCodeAt(pos))) { diff --git a/tests/baselines/reference/bigIntWithTargetES3.errors.txt b/tests/baselines/reference/bigIntWithTargetES3.errors.txt index 6fa938535f1..ed65939999a 100644 --- a/tests/baselines/reference/bigIntWithTargetES3.errors.txt +++ b/tests/baselines/reference/bigIntWithTargetES3.errors.txt @@ -1,21 +1,18 @@ -tests/cases/compiler/bigIntWithTargetES3.ts(5,22): error TS2737: BigInt literals are not available when targeting lower than ESNext. -tests/cases/compiler/bigIntWithTargetES3.ts(5,29): error TS2737: BigInt literals are not available when targeting lower than ESNext. -tests/cases/compiler/bigIntWithTargetES3.ts(5,39): error TS2737: BigInt literals are not available when targeting lower than ESNext. -tests/cases/compiler/bigIntWithTargetES3.ts(5,48): error TS2737: BigInt literals are not available when targeting lower than ESNext. +tests/cases/compiler/bigIntWithTargetES3.ts(3,27): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/bigIntWithTargetES3.ts(4,36): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/bigIntWithTargetES3.ts(5,25): error TS1351: An identifier cannot follow a numeric literal. -==== tests/cases/compiler/bigIntWithTargetES3.ts (4 errors) ==== +==== tests/cases/compiler/bigIntWithTargetES3.ts (3 errors) ==== const normalNumber = 123; // should not error let bigintType: bigint; // should not error let bigintLiteralType: 123n; // should not error when used as type + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. let bigintNegativeLiteralType: -123n; // should not error when used as type + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. const bigintNumber = 123n * 0b1111n + 0o444n * 0x7fn; // each literal should error - ~~~~ -!!! error TS2737: BigInt literals are not available when targeting lower than ESNext. - ~~~~~~~ -!!! error TS2737: BigInt literals are not available when targeting lower than ESNext. - ~~~~~~ -!!! error TS2737: BigInt literals are not available when targeting lower than ESNext. - ~~~~~ -!!! error TS2737: BigInt literals are not available when targeting lower than ESNext. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. \ No newline at end of file diff --git a/tests/baselines/reference/bigintIndex.errors.txt b/tests/baselines/reference/bigintIndex.errors.txt index 50e360a1905..628e2b683be 100644 --- a/tests/baselines/reference/bigintIndex.errors.txt +++ b/tests/baselines/reference/bigintIndex.errors.txt @@ -1,19 +1,21 @@ -tests/cases/compiler/a.ts(2,6): error TS1023: An index signature parameter type must be 'string' or 'number'. tests/cases/compiler/a.ts(8,11): error TS2538: Type '1n' cannot be used as an index type. +tests/cases/compiler/a.ts(8,12): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/a.ts(14,1): error TS2322: Type '123n' is not assignable to type 'string | number | symbol'. +tests/cases/compiler/a.ts(14,10): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/a.ts(17,25): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/a.ts(19,12): error TS2538: Type 'bigint' cannot be used as an index type. tests/cases/compiler/b.ts(2,12): error TS1136: Property assignment expected. +tests/cases/compiler/b.ts(2,13): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/b.ts(2,14): error TS1005: ';' expected. tests/cases/compiler/b.ts(2,19): error TS1128: Declaration or statement expected. tests/cases/compiler/b.ts(3,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/compiler/b.ts(3,14): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/b.ts(4,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. -==== tests/cases/compiler/a.ts (4 errors) ==== +==== tests/cases/compiler/a.ts (6 errors) ==== interface BigIntIndex { [index: bigint]: E; // should error - ~~~~~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. } const arr: number[] = [1, 2, 3]; @@ -22,6 +24,8 @@ tests/cases/compiler/b.ts(4,12): error TS2464: A computed property name must be num = arr[1n]; // should error ~~ !!! error TS2538: Type '1n' cannot be used as an index type. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. let key: keyof any; // should be type "string | number | symbol" key = 123; @@ -30,9 +34,13 @@ tests/cases/compiler/b.ts(4,12): error TS2464: A computed property name must be key = 123n; // should error ~~~ !!! error TS2322: Type '123n' is not assignable to type 'string | number | symbol'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. // Show correct usage of bigint index: explicitly convert to string const bigNum: bigint = 0n; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. const typedArray = new Uint8Array(3); typedArray[bigNum] = 0xAA; // should error ~~~~~~ @@ -42,11 +50,13 @@ tests/cases/compiler/b.ts(4,12): error TS2464: A computed property name must be typedArray[2] = 0xCC; // {1n: 123} is a syntax error; must go in separate file so BigIntIndex error is shown -==== tests/cases/compiler/b.ts (5 errors) ==== +==== tests/cases/compiler/b.ts (7 errors) ==== // BigInt cannot be used as an object literal property const a = {1n: 123}; ~~ !!! error TS1136: Property assignment expected. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~ !!! error TS1005: ';' expected. ~ @@ -54,6 +64,8 @@ tests/cases/compiler/b.ts(4,12): error TS2464: A computed property name must be const b = {[1n]: 456}; ~~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. const c = {[bigNum]: 789}; ~~~~~~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. \ No newline at end of file diff --git a/tests/baselines/reference/bigintWithLib.errors.txt b/tests/baselines/reference/bigintWithLib.errors.txt index 993f43d5a05..7ae0be26a21 100644 --- a/tests/baselines/reference/bigintWithLib.errors.txt +++ b/tests/baselines/reference/bigintWithLib.errors.txt @@ -1,15 +1,30 @@ tests/cases/compiler/bigintWithLib.ts(4,1): error TS2350: Only a void function can be called with the 'new' keyword. +tests/cases/compiler/bigintWithLib.ts(15,35): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/bigintWithLib.ts(15,39): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/bigintWithLib.ts(15,43): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/bigintWithLib.ts(16,33): error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'ArrayBuffer | SharedArrayBuffer'. Type 'number[]' is missing the following properties from type 'SharedArrayBuffer': byteLength, [Symbol.species], [Symbol.toStringTag] tests/cases/compiler/bigintWithLib.ts(21,13): error TS2540: Cannot assign to 'length' because it is a read-only property. +tests/cases/compiler/bigintWithLib.ts(27,37): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/bigintWithLib.ts(27,41): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/bigintWithLib.ts(27,45): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/bigintWithLib.ts(28,35): error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'ArrayBuffer | SharedArrayBuffer'. Type 'number[]' is not assignable to type 'SharedArrayBuffer'. tests/cases/compiler/bigintWithLib.ts(33,13): error TS2540: Cannot assign to 'length' because it is a read-only property. +tests/cases/compiler/bigintWithLib.ts(38,27): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/bigintWithLib.ts(39,27): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/bigintWithLib.ts(40,25): error TS2345: Argument of type '-1' is not assignable to parameter of type 'bigint'. +tests/cases/compiler/bigintWithLib.ts(41,29): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/bigintWithLib.ts(42,29): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/bigintWithLib.ts(43,26): error TS2345: Argument of type '123' is not assignable to parameter of type 'bigint'. +tests/cases/compiler/bigintWithLib.ts(50,13): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/bigintWithLib.ts(51,14): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/bigintWithLib.ts(52,12): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/bigintWithLib.ts(52,18): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/bigintWithLib.ts(53,11): error TS1351: An identifier cannot follow a numeric literal. -==== tests/cases/compiler/bigintWithLib.ts (7 errors) ==== +==== tests/cases/compiler/bigintWithLib.ts (22 errors) ==== // Test BigInt functions let bigintVal: bigint = BigInt(123); bigintVal = BigInt("456"); @@ -27,6 +42,12 @@ tests/cases/compiler/bigintWithLib.ts(43,26): error TS2345: Argument of type '12 let bigIntArray: BigInt64Array = new BigInt64Array(); bigIntArray = new BigInt64Array(10); bigIntArray = new BigInt64Array([1n, 2n, 3n]); + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigIntArray = new BigInt64Array([1, 2, 3]); // should error ~~~~~~~~~ !!! error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'ArrayBuffer | SharedArrayBuffer'. @@ -44,6 +65,12 @@ tests/cases/compiler/bigintWithLib.ts(43,26): error TS2345: Argument of type '12 let bigUintArray: BigUint64Array = new BigUint64Array(); bigUintArray = new BigUint64Array(10); bigUintArray = new BigUint64Array([1n, 2n, 3n]); + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigUintArray = new BigUint64Array([1, 2, 3]); // should error ~~~~~~~~~ !!! error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'ArrayBuffer | SharedArrayBuffer'. @@ -60,12 +87,20 @@ tests/cases/compiler/bigintWithLib.ts(43,26): error TS2345: Argument of type '12 // Test added DataView methods const dataView = new DataView(new ArrayBuffer(80)); dataView.setBigInt64(1, -1n); + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. dataView.setBigInt64(1, -1n, true); + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. dataView.setBigInt64(1, -1); // should error ~~ !!! error TS2345: Argument of type '-1' is not assignable to parameter of type 'bigint'. dataView.setBigUint64(2, 123n); + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. dataView.setBigUint64(2, 123n, true); + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. dataView.setBigUint64(2, 123); // should error ~~~ !!! error TS2345: Argument of type '123' is not assignable to parameter of type 'bigint'. @@ -76,6 +111,16 @@ tests/cases/compiler/bigintWithLib.ts(43,26): error TS2345: Argument of type '12 // Test emitted declarations files const w = 12n; // should emit as const w = 12n + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. const x = -12n; // should emit as const x = -12n + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. const y: 12n = 12n; // should emit type 12n - let z = 12n; // should emit type bigint in declaration file \ No newline at end of file + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + let z = 12n; // should emit type bigint in declaration file + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. \ No newline at end of file diff --git a/tests/baselines/reference/bigintWithoutLib.errors.txt b/tests/baselines/reference/bigintWithoutLib.errors.txt index 7d2c38b29df..3210ce58042 100644 --- a/tests/baselines/reference/bigintWithoutLib.errors.txt +++ b/tests/baselines/reference/bigintWithoutLib.errors.txt @@ -2,18 +2,16 @@ tests/cases/compiler/bigintWithoutLib.ts(4,25): error TS2304: Cannot find name ' tests/cases/compiler/bigintWithoutLib.ts(5,13): error TS2304: Cannot find name 'BigInt'. tests/cases/compiler/bigintWithoutLib.ts(6,5): error TS2304: Cannot find name 'BigInt'. tests/cases/compiler/bigintWithoutLib.ts(7,13): error TS2304: Cannot find name 'BigInt'. -tests/cases/compiler/bigintWithoutLib.ts(7,30): error TS2737: BigInt literals are not available when targeting lower than ESNext. tests/cases/compiler/bigintWithoutLib.ts(8,13): error TS2304: Cannot find name 'BigInt'. -tests/cases/compiler/bigintWithoutLib.ts(8,31): error TS2737: BigInt literals are not available when targeting lower than ESNext. tests/cases/compiler/bigintWithoutLib.ts(9,1): error TS2322: Type 'Object' is not assignable to type 'bigint'. tests/cases/compiler/bigintWithoutLib.ts(11,13): error TS2554: Expected 0 arguments, but got 1. tests/cases/compiler/bigintWithoutLib.ts(15,18): error TS2304: Cannot find name 'BigInt64Array'. tests/cases/compiler/bigintWithoutLib.ts(15,38): error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'? tests/cases/compiler/bigintWithoutLib.ts(16,19): error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'? tests/cases/compiler/bigintWithoutLib.ts(17,19): error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'? -tests/cases/compiler/bigintWithoutLib.ts(17,34): error TS2737: BigInt literals are not available when targeting lower than ESNext. -tests/cases/compiler/bigintWithoutLib.ts(17,38): error TS2737: BigInt literals are not available when targeting lower than ESNext. -tests/cases/compiler/bigintWithoutLib.ts(17,42): error TS2737: BigInt literals are not available when targeting lower than ESNext. +tests/cases/compiler/bigintWithoutLib.ts(17,35): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/bigintWithoutLib.ts(17,39): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/bigintWithoutLib.ts(17,43): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/bigintWithoutLib.ts(18,19): error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'? tests/cases/compiler/bigintWithoutLib.ts(19,19): error TS2304: Cannot find name 'BigInt64Array'. tests/cases/compiler/bigintWithoutLib.ts(20,19): error TS2304: Cannot find name 'BigInt64Array'. @@ -22,22 +20,22 @@ tests/cases/compiler/bigintWithoutLib.ts(27,19): error TS2304: Cannot find name tests/cases/compiler/bigintWithoutLib.ts(27,40): error TS2304: Cannot find name 'BigUint64Array'. tests/cases/compiler/bigintWithoutLib.ts(28,20): error TS2304: Cannot find name 'BigUint64Array'. tests/cases/compiler/bigintWithoutLib.ts(29,20): error TS2304: Cannot find name 'BigUint64Array'. -tests/cases/compiler/bigintWithoutLib.ts(29,36): error TS2737: BigInt literals are not available when targeting lower than ESNext. -tests/cases/compiler/bigintWithoutLib.ts(29,40): error TS2737: BigInt literals are not available when targeting lower than ESNext. -tests/cases/compiler/bigintWithoutLib.ts(29,44): error TS2737: BigInt literals are not available when targeting lower than ESNext. +tests/cases/compiler/bigintWithoutLib.ts(29,37): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/bigintWithoutLib.ts(29,41): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/bigintWithoutLib.ts(29,45): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/bigintWithoutLib.ts(30,20): error TS2304: Cannot find name 'BigUint64Array'. tests/cases/compiler/bigintWithoutLib.ts(31,20): error TS2304: Cannot find name 'BigUint64Array'. tests/cases/compiler/bigintWithoutLib.ts(32,20): error TS2304: Cannot find name 'BigUint64Array'. tests/cases/compiler/bigintWithoutLib.ts(33,20): error TS2304: Cannot find name 'BigUint64Array'. tests/cases/compiler/bigintWithoutLib.ts(40,10): error TS2339: Property 'setBigInt64' does not exist on type 'DataView'. -tests/cases/compiler/bigintWithoutLib.ts(40,26): error TS2737: BigInt literals are not available when targeting lower than ESNext. +tests/cases/compiler/bigintWithoutLib.ts(40,27): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/bigintWithoutLib.ts(41,10): error TS2339: Property 'setBigInt64' does not exist on type 'DataView'. -tests/cases/compiler/bigintWithoutLib.ts(41,26): error TS2737: BigInt literals are not available when targeting lower than ESNext. +tests/cases/compiler/bigintWithoutLib.ts(41,27): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/bigintWithoutLib.ts(42,10): error TS2339: Property 'setBigInt64' does not exist on type 'DataView'. tests/cases/compiler/bigintWithoutLib.ts(43,10): error TS2339: Property 'setBigUint64' does not exist on type 'DataView'. -tests/cases/compiler/bigintWithoutLib.ts(43,26): error TS2737: BigInt literals are not available when targeting lower than ESNext. +tests/cases/compiler/bigintWithoutLib.ts(43,29): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/bigintWithoutLib.ts(44,10): error TS2339: Property 'setBigUint64' does not exist on type 'DataView'. -tests/cases/compiler/bigintWithoutLib.ts(44,26): error TS2737: BigInt literals are not available when targeting lower than ESNext. +tests/cases/compiler/bigintWithoutLib.ts(44,29): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/bigintWithoutLib.ts(45,10): error TS2339: Property 'setBigUint64' does not exist on type 'DataView'. tests/cases/compiler/bigintWithoutLib.ts(46,22): error TS2339: Property 'getBigInt64' does not exist on type 'DataView'. tests/cases/compiler/bigintWithoutLib.ts(47,22): error TS2339: Property 'getBigInt64' does not exist on type 'DataView'. @@ -45,7 +43,7 @@ tests/cases/compiler/bigintWithoutLib.ts(48,22): error TS2339: Property 'getBigU tests/cases/compiler/bigintWithoutLib.ts(49,22): error TS2339: Property 'getBigUint64' does not exist on type 'DataView'. -==== tests/cases/compiler/bigintWithoutLib.ts (45 errors) ==== +==== tests/cases/compiler/bigintWithoutLib.ts (43 errors) ==== // Every line should error because these builtins are not declared // Test BigInt functions @@ -61,13 +59,9 @@ tests/cases/compiler/bigintWithoutLib.ts(49,22): error TS2339: Property 'getBigU bigintVal = BigInt.asIntN(8, 0xFFFFn); ~~~~~~ !!! error TS2304: Cannot find name 'BigInt'. - ~~~~~~~ -!!! error TS2737: BigInt literals are not available when targeting lower than ESNext. bigintVal = BigInt.asUintN(8, 0xFFFFn); ~~~~~~ !!! error TS2304: Cannot find name 'BigInt'. - ~~~~~~~ -!!! error TS2737: BigInt literals are not available when targeting lower than ESNext. bigintVal = bigintVal.valueOf(); // should error - bigintVal inferred as {} ~~~~~~~~~ !!! error TS2322: Type 'Object' is not assignable to type 'bigint'. @@ -92,12 +86,12 @@ tests/cases/compiler/bigintWithoutLib.ts(49,22): error TS2339: Property 'getBigU ~~~~~~~~~~~~~ !!! error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'? !!! related TS2728 tests/cases/compiler/bigintWithoutLib.ts:15:5: 'bigIntArray' is declared here. - ~~ -!!! error TS2737: BigInt literals are not available when targeting lower than ESNext. - ~~ -!!! error TS2737: BigInt literals are not available when targeting lower than ESNext. - ~~ -!!! error TS2737: BigInt literals are not available when targeting lower than ESNext. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigIntArray = new BigInt64Array([1, 2, 3]); ~~~~~~~~~~~~~ !!! error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'? @@ -127,12 +121,12 @@ tests/cases/compiler/bigintWithoutLib.ts(49,22): error TS2339: Property 'getBigU bigUintArray = new BigUint64Array([1n, 2n, 3n]); ~~~~~~~~~~~~~~ !!! error TS2304: Cannot find name 'BigUint64Array'. - ~~ -!!! error TS2737: BigInt literals are not available when targeting lower than ESNext. - ~~ -!!! error TS2737: BigInt literals are not available when targeting lower than ESNext. - ~~ -!!! error TS2737: BigInt literals are not available when targeting lower than ESNext. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigUintArray = new BigUint64Array([1, 2, 3]); ~~~~~~~~~~~~~~ !!! error TS2304: Cannot find name 'BigUint64Array'. @@ -154,26 +148,26 @@ tests/cases/compiler/bigintWithoutLib.ts(49,22): error TS2339: Property 'getBigU dataView.setBigInt64(1, -1n); ~~~~~~~~~~~ !!! error TS2339: Property 'setBigInt64' does not exist on type 'DataView'. - ~~ -!!! error TS2737: BigInt literals are not available when targeting lower than ESNext. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. dataView.setBigInt64(1, -1n, true); ~~~~~~~~~~~ !!! error TS2339: Property 'setBigInt64' does not exist on type 'DataView'. - ~~ -!!! error TS2737: BigInt literals are not available when targeting lower than ESNext. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. dataView.setBigInt64(1, -1); ~~~~~~~~~~~ !!! error TS2339: Property 'setBigInt64' does not exist on type 'DataView'. dataView.setBigUint64(2, 123n); ~~~~~~~~~~~~ !!! error TS2339: Property 'setBigUint64' does not exist on type 'DataView'. - ~~~~ -!!! error TS2737: BigInt literals are not available when targeting lower than ESNext. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. dataView.setBigUint64(2, 123n, true); ~~~~~~~~~~~~ !!! error TS2339: Property 'setBigUint64' does not exist on type 'DataView'. - ~~~~ -!!! error TS2737: BigInt literals are not available when targeting lower than ESNext. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. dataView.setBigUint64(2, 123); ~~~~~~~~~~~~ !!! error TS2339: Property 'setBigUint64' does not exist on type 'DataView'. diff --git a/tests/baselines/reference/identifierStartAfterNumericLiteral.errors.txt b/tests/baselines/reference/identifierStartAfterNumericLiteral.errors.txt new file mode 100644 index 00000000000..03e408a6486 --- /dev/null +++ b/tests/baselines/reference/identifierStartAfterNumericLiteral.errors.txt @@ -0,0 +1,74 @@ +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(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(11,2): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/identifierStartAfterNumericLiteral.ts(12,2): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/identifierStartAfterNumericLiteral.ts(12,3): error TS1005: ';' expected. +tests/cases/compiler/identifierStartAfterNumericLiteral.ts(13,2): error TS1351: An identifier cannot follow a numeric literal. +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 (19 errors) ==== + let valueIn = 3in[null]; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + + 3a[null] + ~ +!!! error TS1351: An identifier cannot 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. + 3in[null] + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + 3en[null] + +!!! error TS1124: Digit expected. + ~ +!!! error TS2304: Cannot find name 'n'. + 1a + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS2304: Cannot find name 'a'. + 1e + +!!! error TS1124: Digit expected. + 1e9 + 1ee + +!!! error TS1124: Digit expected. + ~ +!!! error TS2304: Cannot find name 'e'. + 1n + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + 2n2 + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1005: ';' expected. + 2na + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS2304: Cannot find name 'a'. + \ No newline at end of file diff --git a/tests/baselines/reference/identifierStartAfterNumericLiteral.js b/tests/baselines/reference/identifierStartAfterNumericLiteral.js new file mode 100644 index 00000000000..0ec84716c2c --- /dev/null +++ b/tests/baselines/reference/identifierStartAfterNumericLiteral.js @@ -0,0 +1,35 @@ +//// [identifierStartAfterNumericLiteral.ts] +let valueIn = 3in[null]; + +3a[null] +3e[null] +3in[null] +3en[null] +1a +1e +1e9 +1ee +1n +2n2 +2na + + +//// [identifierStartAfterNumericLiteral.js] +var valueIn = 3 in [null]; +3; +a[null]; +3e[null]; +3 in [null]; +3e; +n[null]; +1; +a; +1e; +1e9; +1e; +e; +1n; +2n; +2; +2n; +a; diff --git a/tests/baselines/reference/identifierStartAfterNumericLiteral.symbols b/tests/baselines/reference/identifierStartAfterNumericLiteral.symbols new file mode 100644 index 00000000000..71b253dbecc --- /dev/null +++ b/tests/baselines/reference/identifierStartAfterNumericLiteral.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/identifierStartAfterNumericLiteral.ts === +let valueIn = 3in[null]; +>valueIn : Symbol(valueIn, Decl(identifierStartAfterNumericLiteral.ts, 0, 3)) + +3a[null] +3e[null] +3in[null] +3en[null] +1a +1e +1e9 +1ee +1n +2n2 +2na + diff --git a/tests/baselines/reference/identifierStartAfterNumericLiteral.types b/tests/baselines/reference/identifierStartAfterNumericLiteral.types new file mode 100644 index 00000000000..b31c9ee8d11 --- /dev/null +++ b/tests/baselines/reference/identifierStartAfterNumericLiteral.types @@ -0,0 +1,56 @@ +=== tests/cases/compiler/identifierStartAfterNumericLiteral.ts === +let valueIn = 3in[null]; +>valueIn : boolean +>3in[null] : boolean +>3 : 3 +>[null] : null[] +>null : null + +3a[null] +>3 : 3 +>a[null] : any +>a : any +>null : null + +3e[null] +>3e[null] : any +>3e : 3 +>null : null + +3in[null] +>3in[null] : boolean +>3 : 3 +>[null] : null[] +>null : null + +3en[null] +>3e : 3 +>n[null] : any +>n : any +>null : null + +1a +>1 : 1 +>a : any + +1e +>1e : 1 + +1e9 +>1e9 : 1000000000 + +1ee +>1e : 1 +>e : any + +1n +>1n : 1n + +2n2 +>2n : 2n +>2 : 2 + +2na +>2n : 2n +>a : any + diff --git a/tests/baselines/reference/numberVsBigIntOperations.errors.txt b/tests/baselines/reference/numberVsBigIntOperations.errors.txt index fbd49ddd091..7f97bcc78a6 100644 --- a/tests/baselines/reference/numberVsBigIntOperations.errors.txt +++ b/tests/baselines/reference/numberVsBigIntOperations.errors.txt @@ -1,51 +1,124 @@ +tests/cases/compiler/numberVsBigIntOperations.ts(2,15): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(3,11): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(3,14): error TS2322: Type '2' is not assignable to type 'bigint'. tests/cases/compiler/numberVsBigIntOperations.ts(3,26): error TS2322: Type '1n' is not assignable to type 'number'. +tests/cases/compiler/numberVsBigIntOperations.ts(3,33): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(4,12): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(4,15): error TS2365: Operator '+=' cannot be applied to types 'bigint' and '2'. tests/cases/compiler/numberVsBigIntOperations.ts(4,28): error TS2365: Operator '+=' cannot be applied to types 'number' and '1n'. +tests/cases/compiler/numberVsBigIntOperations.ts(4,36): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(5,12): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(5,15): error TS2365: Operator '-=' cannot be applied to types 'bigint' and '2'. tests/cases/compiler/numberVsBigIntOperations.ts(5,28): error TS2365: Operator '-=' cannot be applied to types 'number' and '1n'. +tests/cases/compiler/numberVsBigIntOperations.ts(5,36): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(6,12): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(6,15): error TS2365: Operator '*=' cannot be applied to types 'bigint' and '2'. tests/cases/compiler/numberVsBigIntOperations.ts(6,28): error TS2365: Operator '*=' cannot be applied to types 'number' and '1n'. +tests/cases/compiler/numberVsBigIntOperations.ts(6,36): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(7,12): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(7,15): error TS2365: Operator '/=' cannot be applied to types 'bigint' and '2'. tests/cases/compiler/numberVsBigIntOperations.ts(7,28): error TS2365: Operator '/=' cannot be applied to types 'number' and '1n'. +tests/cases/compiler/numberVsBigIntOperations.ts(7,36): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(8,12): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(8,15): error TS2365: Operator '%=' cannot be applied to types 'bigint' and '2'. tests/cases/compiler/numberVsBigIntOperations.ts(8,28): error TS2365: Operator '%=' cannot be applied to types 'number' and '1n'. +tests/cases/compiler/numberVsBigIntOperations.ts(8,36): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(9,13): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(9,16): error TS2365: Operator '**=' cannot be applied to types 'bigint' and '2'. tests/cases/compiler/numberVsBigIntOperations.ts(9,30): error TS2365: Operator '**=' cannot be applied to types 'number' and '1n'. +tests/cases/compiler/numberVsBigIntOperations.ts(9,39): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(10,13): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(10,16): error TS2365: Operator '<<=' cannot be applied to types 'bigint' and '2'. tests/cases/compiler/numberVsBigIntOperations.ts(10,30): error TS2365: Operator '<<=' cannot be applied to types 'number' and '1n'. +tests/cases/compiler/numberVsBigIntOperations.ts(10,39): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(11,13): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(11,16): error TS2365: Operator '>>=' cannot be applied to types 'bigint' and '2'. tests/cases/compiler/numberVsBigIntOperations.ts(11,30): error TS2365: Operator '>>=' cannot be applied to types 'number' and '1n'. +tests/cases/compiler/numberVsBigIntOperations.ts(11,39): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(12,12): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(12,15): error TS2365: Operator '&=' cannot be applied to types 'bigint' and '2'. tests/cases/compiler/numberVsBigIntOperations.ts(12,28): error TS2365: Operator '&=' cannot be applied to types 'number' and '1n'. +tests/cases/compiler/numberVsBigIntOperations.ts(12,36): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(13,12): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(13,15): error TS2365: Operator '^=' cannot be applied to types 'bigint' and '2'. tests/cases/compiler/numberVsBigIntOperations.ts(13,28): error TS2365: Operator '^=' cannot be applied to types 'number' and '1n'. +tests/cases/compiler/numberVsBigIntOperations.ts(13,36): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(14,12): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(14,15): error TS2365: Operator '|=' cannot be applied to types 'bigint' and '2'. tests/cases/compiler/numberVsBigIntOperations.ts(14,28): error TS2365: Operator '|=' cannot be applied to types 'number' and '1n'. +tests/cases/compiler/numberVsBigIntOperations.ts(14,36): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(15,11): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(15,16): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(15,32): error TS2365: Operator '+' cannot be applied to types '1' and '2n'. +tests/cases/compiler/numberVsBigIntOperations.ts(15,37): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(15,40): error TS2365: Operator '+' cannot be applied to types '1n' and '2'. +tests/cases/compiler/numberVsBigIntOperations.ts(15,41): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(16,11): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(16,16): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(16,32): error TS2365: Operator '-' cannot be applied to types '1' and '2n'. +tests/cases/compiler/numberVsBigIntOperations.ts(16,37): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(16,40): error TS2365: Operator '-' cannot be applied to types '1n' and '2'. +tests/cases/compiler/numberVsBigIntOperations.ts(16,41): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(17,11): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(17,16): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(17,32): error TS2365: Operator '*' cannot be applied to types '1' and '2n'. +tests/cases/compiler/numberVsBigIntOperations.ts(17,37): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(17,40): error TS2365: Operator '*' cannot be applied to types '1n' and '2'. +tests/cases/compiler/numberVsBigIntOperations.ts(17,41): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(18,11): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(18,16): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(18,32): error TS2365: Operator '/' cannot be applied to types '1' and '2n'. +tests/cases/compiler/numberVsBigIntOperations.ts(18,37): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(18,40): error TS2365: Operator '/' cannot be applied to types '1n' and '2'. +tests/cases/compiler/numberVsBigIntOperations.ts(18,41): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(19,11): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(19,16): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(19,32): error TS2365: Operator '%' cannot be applied to types '1' and '2n'. +tests/cases/compiler/numberVsBigIntOperations.ts(19,37): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(19,40): error TS2365: Operator '%' cannot be applied to types '1n' and '2'. +tests/cases/compiler/numberVsBigIntOperations.ts(19,41): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(20,11): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(20,17): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(20,34): error TS2365: Operator '**' cannot be applied to types '1' and '2n'. +tests/cases/compiler/numberVsBigIntOperations.ts(20,40): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(20,43): error TS2365: Operator '**' cannot be applied to types '1n' and '2'. +tests/cases/compiler/numberVsBigIntOperations.ts(20,44): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(21,11): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(21,16): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(21,32): error TS2365: Operator '&' cannot be applied to types '1' and '2n'. +tests/cases/compiler/numberVsBigIntOperations.ts(21,37): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(21,40): error TS2365: Operator '&' cannot be applied to types '1n' and '2'. +tests/cases/compiler/numberVsBigIntOperations.ts(21,41): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(22,11): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(22,16): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(22,32): error TS2365: Operator '|' cannot be applied to types '1' and '2n'. +tests/cases/compiler/numberVsBigIntOperations.ts(22,37): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(22,40): error TS2365: Operator '|' cannot be applied to types '1n' and '2'. +tests/cases/compiler/numberVsBigIntOperations.ts(22,41): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(23,11): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(23,16): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(23,32): error TS2365: Operator '^' cannot be applied to types '1' and '2n'. +tests/cases/compiler/numberVsBigIntOperations.ts(23,37): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(23,40): error TS2365: Operator '^' cannot be applied to types '1n' and '2'. +tests/cases/compiler/numberVsBigIntOperations.ts(23,41): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(24,11): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(24,17): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(24,34): error TS2365: Operator '<<' cannot be applied to types '1' and '2n'. +tests/cases/compiler/numberVsBigIntOperations.ts(24,40): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(24,43): error TS2365: Operator '<<' cannot be applied to types '1n' and '2'. +tests/cases/compiler/numberVsBigIntOperations.ts(24,44): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(25,11): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(25,17): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(25,34): error TS2365: Operator '>>' cannot be applied to types '1' and '2n'. +tests/cases/compiler/numberVsBigIntOperations.ts(25,40): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(25,43): error TS2365: Operator '>>' cannot be applied to types '1n' and '2'. +tests/cases/compiler/numberVsBigIntOperations.ts(25,44): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(29,37): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(29,68): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(38,1): error TS2365: Operator '>>>=' cannot be applied to types 'bigint' and '1n'. +tests/cases/compiler/numberVsBigIntOperations.ts(38,14): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(39,10): error TS2365: Operator '>>>' cannot be applied to types 'bigint' and '1n'. +tests/cases/compiler/numberVsBigIntOperations.ts(39,22): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(40,8): error TS2736: Operator '+' cannot be applied to type 'bigint'. tests/cases/compiler/numberVsBigIntOperations.ts(50,10): error TS2367: This condition will always return 'false' since the types 'bigint' and 'number' have no overlap. tests/cases/compiler/numberVsBigIntOperations.ts(51,10): error TS2367: This condition will always return 'true' since the types 'bigint' and 'number' have no overlap. @@ -55,137 +128,286 @@ tests/cases/compiler/numberVsBigIntOperations.ts(56,7): error TS2362: The left-h tests/cases/compiler/numberVsBigIntOperations.ts(56,27): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/compiler/numberVsBigIntOperations.ts(57,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/compiler/numberVsBigIntOperations.ts(57,1): error TS2365: Operator '&' cannot be applied to types '"3"' and '5n'. +tests/cases/compiler/numberVsBigIntOperations.ts(57,8): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(57,11): error TS2365: Operator '**' cannot be applied to types '2n' and 'false'. +tests/cases/compiler/numberVsBigIntOperations.ts(57,12): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/numberVsBigIntOperations.ts(57,17): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/compiler/numberVsBigIntOperations.ts(60,1): error TS2365: Operator '+' cannot be applied to types 'number | bigint' and 'number | bigint'. tests/cases/compiler/numberVsBigIntOperations.ts(61,1): error TS2365: Operator '<<' cannot be applied to types 'number | bigint' and 'number | bigint'. tests/cases/compiler/numberVsBigIntOperations.ts(70,2): error TS2736: Operator '+' cannot be applied to type 'number | bigint'. -tests/cases/compiler/numberVsBigIntOperations.ts(86,7): error TS1155: 'const' declarations must be initialized. -tests/cases/compiler/numberVsBigIntOperations.ts(93,7): error TS1155: 'const' declarations must be initialized. +tests/cases/compiler/numberVsBigIntOperations.ts(84,22): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(84,27): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(84,47): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(84,52): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(86,26): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(91,24): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/numberVsBigIntOperations.ts(93,22): error TS1351: An identifier cannot follow a numeric literal. -==== tests/cases/compiler/numberVsBigIntOperations.ts (64 errors) ==== +==== tests/cases/compiler/numberVsBigIntOperations.ts (144 errors) ==== // Cannot mix bigints and numbers let bigInt = 1n, num = 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt = 1n; bigInt = 2; num = 1n; num = 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~ !!! error TS2322: Type '2' is not assignable to type 'bigint'. ~~~ !!! error TS2322: Type '1n' is not assignable to type 'number'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt += 1n; bigInt += 2; num += 1n; num += 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~~~~~~ !!! error TS2365: Operator '+=' cannot be applied to types 'bigint' and '2'. ~~~~~~~~~ !!! error TS2365: Operator '+=' cannot be applied to types 'number' and '1n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt -= 1n; bigInt -= 2; num -= 1n; num -= 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~~~~~~ !!! error TS2365: Operator '-=' cannot be applied to types 'bigint' and '2'. ~~~~~~~~~ !!! error TS2365: Operator '-=' cannot be applied to types 'number' and '1n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt *= 1n; bigInt *= 2; num *= 1n; num *= 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~~~~~~ !!! error TS2365: Operator '*=' cannot be applied to types 'bigint' and '2'. ~~~~~~~~~ !!! error TS2365: Operator '*=' cannot be applied to types 'number' and '1n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt /= 1n; bigInt /= 2; num /= 1n; num /= 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~~~~~~ !!! error TS2365: Operator '/=' cannot be applied to types 'bigint' and '2'. ~~~~~~~~~ !!! error TS2365: Operator '/=' cannot be applied to types 'number' and '1n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt %= 1n; bigInt %= 2; num %= 1n; num %= 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~~~~~~ !!! error TS2365: Operator '%=' cannot be applied to types 'bigint' and '2'. ~~~~~~~~~ !!! error TS2365: Operator '%=' cannot be applied to types 'number' and '1n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt **= 1n; bigInt **= 2; num **= 1n; num **= 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~~~~~~~ !!! error TS2365: Operator '**=' cannot be applied to types 'bigint' and '2'. ~~~~~~~~~~ !!! error TS2365: Operator '**=' cannot be applied to types 'number' and '1n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt <<= 1n; bigInt <<= 2; num <<= 1n; num <<= 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~~~~~~~ !!! error TS2365: Operator '<<=' cannot be applied to types 'bigint' and '2'. ~~~~~~~~~~ !!! error TS2365: Operator '<<=' cannot be applied to types 'number' and '1n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt >>= 1n; bigInt >>= 2; num >>= 1n; num >>= 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~~~~~~~ !!! error TS2365: Operator '>>=' cannot be applied to types 'bigint' and '2'. ~~~~~~~~~~ !!! error TS2365: Operator '>>=' cannot be applied to types 'number' and '1n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt &= 1n; bigInt &= 2; num &= 1n; num &= 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~~~~~~ !!! error TS2365: Operator '&=' cannot be applied to types 'bigint' and '2'. ~~~~~~~~~ !!! error TS2365: Operator '&=' cannot be applied to types 'number' and '1n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt ^= 1n; bigInt ^= 2; num ^= 1n; num ^= 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~~~~~~ !!! error TS2365: Operator '^=' cannot be applied to types 'bigint' and '2'. ~~~~~~~~~ !!! error TS2365: Operator '^=' cannot be applied to types 'number' and '1n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt |= 1n; bigInt |= 2; num |= 1n; num |= 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~~~~~~ !!! error TS2365: Operator '|=' cannot be applied to types 'bigint' and '2'. ~~~~~~~~~ !!! error TS2365: Operator '|=' cannot be applied to types 'number' and '1n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt = 1n + 2n; num = 1 + 2; 1 + 2n; 1n + 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types '1' and '2n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~ !!! error TS2365: Operator '+' cannot be applied to types '1n' and '2'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt = 1n - 2n; num = 1 - 2; 1 - 2n; 1n - 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~ !!! error TS2365: Operator '-' cannot be applied to types '1' and '2n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~ !!! error TS2365: Operator '-' cannot be applied to types '1n' and '2'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt = 1n * 2n; num = 1 * 2; 1 * 2n; 1n * 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~ !!! error TS2365: Operator '*' cannot be applied to types '1' and '2n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~ !!! error TS2365: Operator '*' cannot be applied to types '1n' and '2'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt = 1n / 2n; num = 1 / 2; 1 / 2n; 1n / 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~ !!! error TS2365: Operator '/' cannot be applied to types '1' and '2n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~ !!! error TS2365: Operator '/' cannot be applied to types '1n' and '2'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt = 1n % 2n; num = 1 % 2; 1 % 2n; 1n % 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~ !!! error TS2365: Operator '%' cannot be applied to types '1' and '2n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~ !!! error TS2365: Operator '%' cannot be applied to types '1n' and '2'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt = 1n ** 2n; num = 1 ** 2; 1 ** 2n; 1n ** 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~~ !!! error TS2365: Operator '**' cannot be applied to types '1' and '2n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~~ !!! error TS2365: Operator '**' cannot be applied to types '1n' and '2'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt = 1n & 2n; num = 1 & 2; 1 & 2n; 1n & 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~ !!! error TS2365: Operator '&' cannot be applied to types '1' and '2n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~ !!! error TS2365: Operator '&' cannot be applied to types '1n' and '2'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt = 1n | 2n; num = 1 | 2; 1 | 2n; 1n | 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~ !!! error TS2365: Operator '|' cannot be applied to types '1' and '2n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~ !!! error TS2365: Operator '|' cannot be applied to types '1n' and '2'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt = 1n ^ 2n; num = 1 ^ 2; 1 ^ 2n; 1n ^ 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~ !!! error TS2365: Operator '^' cannot be applied to types '1' and '2n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~ !!! error TS2365: Operator '^' cannot be applied to types '1n' and '2'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt = 1n << 2n; num = 1 << 2; 1 << 2n; 1n << 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~~ !!! error TS2365: Operator '<<' cannot be applied to types '1' and '2n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~~ !!! error TS2365: Operator '<<' cannot be applied to types '1n' and '2'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt = 1n >> 2n; num = 1 >> 2; 1 >> 2n; 1n >> 2; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~~ !!! error TS2365: Operator '>>' cannot be applied to types '1' and '2n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~~ !!! error TS2365: Operator '>>' cannot be applied to types '1n' and '2'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. // Plus should still coerce to strings let str: string; str = "abc" + 123; str = "abc" + 123n; str = 123 + "abc"; str = 123n + "abc"; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. // Unary operations allowed on bigints and numbers bigInt = bigInt++; bigInt = ++bigInt; num = num++; num = ++num; @@ -197,9 +419,13 @@ tests/cases/compiler/numberVsBigIntOperations.ts(93,7): error TS1155: 'const' de bigInt >>>= 1n; num >>>= 2; ~~~~~~~~~~~~~~ !!! error TS2365: Operator '>>>=' cannot be applied to types 'bigint' and '1n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. bigInt = bigInt >>> 1n; num = num >>> 2; ~~~~~~~~~~~~~ !!! error TS2365: Operator '>>>' cannot be applied to types 'bigint' and '1n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. num = +bigInt; num = +num; num = +"3"; ~~~~~~ !!! error TS2736: Operator '+' cannot be applied to type 'bigint'. @@ -236,8 +462,12 @@ tests/cases/compiler/numberVsBigIntOperations.ts(93,7): error TS1155: 'const' de !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. ~~~~~~~~ !!! error TS2365: Operator '&' cannot be applied to types '"3"' and '5n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~~~~~~~ !!! error TS2365: Operator '**' cannot be applied to types '2n' and 'false'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~ !!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. num = ~"3"; num = -false; // should infer number @@ -273,17 +503,27 @@ tests/cases/compiler/numberVsBigIntOperations.ts(93,7): error TS1155: 'const' de // Distinguishing numbers from bigints with typeof const isBigInt: (x: 0n | 1n) => bigint = (x: 0n | 1n) => x; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. const isNumber: (x: 0 | 1) => number = (x: 0 | 1) => x; const zeroOrBigOne: 0 | 1n; - ~~~~~~~~~~~~ -!!! error TS1155: 'const' declarations must be initialized. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. if (typeof zeroOrBigOne === "bigint") isBigInt(zeroOrBigOne); else isNumber(zeroOrBigOne); // Distinguishing truthy from falsy const isOne = (x: 1 | 1n) => x; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. if (zeroOrBigOne) isOne(zeroOrBigOne); const bigZeroOrOne: 0n | 1; - ~~~~~~~~~~~~ -!!! error TS1155: 'const' declarations must be initialized. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. if (bigZeroOrOne) isOne(bigZeroOrOne); \ No newline at end of file diff --git a/tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.errors.txt b/tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.errors.txt index ca85c992fa4..42561707d56 100644 --- a/tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.errors.txt +++ b/tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts(3,3): error TS1005: ';' expected. -tests/cases/compiler/numericLiteralsWithTrailingDecimalPoints01.ts(9,15): error TS1005: ',' expected. +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(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 TS1005: ';' expected. + ~ +!!! error TS1351: An identifier cannot 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 TS1005: ',' expected. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~ !!! error TS1005: ',' expected. ~ diff --git a/tests/baselines/reference/parseBigInt.errors.txt b/tests/baselines/reference/parseBigInt.errors.txt index 9c273542c0b..df4d9dce4aa 100644 --- a/tests/baselines/reference/parseBigInt.errors.txt +++ b/tests/baselines/reference/parseBigInt.errors.txt @@ -1,40 +1,65 @@ +tests/cases/compiler/parseBigInt.ts(5,32): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/parseBigInt.ts(11,38): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/parseBigInt.ts(17,33): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/parseBigInt.ts(42,17): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/parseBigInt.ts(43,18): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/parseBigInt.ts(46,17): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/parseBigInt.ts(46,23): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/parseBigInt.ts(47,22): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/parseBigInt.ts(51,20): error TS2736: Operator '+' cannot be applied to type '123n'. +tests/cases/compiler/parseBigInt.ts(51,23): error TS1351: An identifier cannot follow a numeric literal. 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 TS1005: ',' expected. -tests/cases/compiler/parseBigInt.ts(58,22): error TS1005: ',' expected. -tests/cases/compiler/parseBigInt.ts(59,28): 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(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. tests/cases/compiler/parseBigInt.ts(63,26): error TS2304: Cannot find name '_123n'. tests/cases/compiler/parseBigInt.ts(64,30): error TS6188: Numeric separators are not allowed here. +tests/cases/compiler/parseBigInt.ts(64,31): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/parseBigInt.ts(65,33): error TS6189: Multiple consecutive numeric separators are not permitted. +tests/cases/compiler/parseBigInt.ts(65,37): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/parseBigInt.ts(68,28): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/parseBigInt.ts(68,33): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/parseBigInt.ts(68,38): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/parseBigInt.ts(68,58): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/parseBigInt.ts(69,15): error TS2345: Argument of type '0n' is not assignable to parameter of type '1n | 3n | 2n'. +tests/cases/compiler/parseBigInt.ts(69,16): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/parseBigInt.ts(69,35): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/parseBigInt.ts(69,54): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/parseBigInt.ts(69,73): error TS1351: An identifier cannot follow a numeric literal. tests/cases/compiler/parseBigInt.ts(70,15): error TS2345: Argument of type '0' is not assignable to parameter of type '1n | 3n | 2n'. tests/cases/compiler/parseBigInt.ts(70,34): error TS2345: Argument of type '1' is not assignable to parameter of type '1n | 3n | 2n'. tests/cases/compiler/parseBigInt.ts(70,53): error TS2345: Argument of type '2' is not assignable to parameter of type '1n | 3n | 2n'. tests/cases/compiler/parseBigInt.ts(70,72): error TS2345: Argument of type '3' is not assignable to parameter of type '1n | 3n | 2n'. -==== tests/cases/compiler/parseBigInt.ts (17 errors) ==== +==== tests/cases/compiler/parseBigInt.ts (36 errors) ==== // All bases should allow "n" suffix const bin = 0b101, binBig = 0b101n; // 5, 5n const oct = 0o567, octBig = 0o567n; // 375, 375n const hex = 0xC0B, hexBig = 0xC0Bn; // 3083, 3083n const dec = 123, decBig = 123n; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. // Test literals whose values overflow a 53-bit integer // These should be represented exactly in the emitted JS const largeBin = 0b10101010101010101010101010101010101010101010101010101010101n; // 384307168202282325n const largeOct = 0o123456712345671234567n; // 1505852261029722487n const largeDec = 12345678091234567890n; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. const largeHex = 0x1234567890abcdefn; // 1311768467294899695n // Test literals with separators const separatedBin = 0b010_10_1n; // 21n const separatedOct = 0o1234_567n; // 342391n const separatedDec = 123_456_789n; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. const separatedHex = 0x0_abcdefn; // 11259375n // Test parsing literals of different bit sizes @@ -60,17 +85,29 @@ tests/cases/compiler/parseBigInt.ts(70,72): error TS2345: Argument of type '3' i // Test negative literals const neg = -123n; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. const negHex: -16n = -0x10n; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. // Test normalization of bigints -- all of these should succeed const negZero: 0n = -0n; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. const baseChange: 255n = 0xFFn; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. const leadingZeros: 0xFFn = 0x000000FFn; // Plus not allowed on literals const unaryPlus = +123n; ~~~~ !!! error TS2736: Operator '+' cannot be applied to type '123n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. const unaryPlusHex = +0x123n; ~~~~~~ !!! error TS2736: Operator '+' cannot be applied to type '291n'. @@ -82,13 +119,13 @@ tests/cases/compiler/parseBigInt.ts(70,72): error TS2345: Argument of type '3' i !!! error TS1005: ',' expected. { const scientific = 1e2n; } ~ -!!! error TS1005: ',' expected. +!!! error TS1351: An identifier cannot follow a numeric literal. { const decimal = 4.1n; } ~ -!!! error TS1005: ',' expected. +!!! error TS1351: An identifier cannot follow a numeric literal. { const leadingDecimal = .1n; } ~ -!!! error TS1005: ',' expected. +!!! error TS1351: An identifier cannot follow a numeric literal. const emptyBinary = 0bn; // should error but infer 0n !!! error TS1177: Binary digit expected. @@ -104,15 +141,35 @@ tests/cases/compiler/parseBigInt.ts(70,72): error TS2345: Argument of type '3' i const trailingSeparator = 123_n; ~ !!! error TS6188: Numeric separators are not allowed here. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. const doubleSeparator = 123_456__789n; ~ !!! error TS6189: Multiple consecutive numeric separators are not permitted. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. // Using literals as types const oneTwoOrThree = (x: 1n | 2n | 3n): bigint => x ** 2n; + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. oneTwoOrThree(0n); oneTwoOrThree(1n); oneTwoOrThree(2n); oneTwoOrThree(3n); ~~ !!! error TS2345: Argument of type '0n' is not assignable to parameter of type '1n | 3n | 2n'. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. oneTwoOrThree(0); oneTwoOrThree(1); oneTwoOrThree(2); oneTwoOrThree(3); ~ !!! error TS2345: Argument of type '0' is not assignable to parameter of type '1n | 3n | 2n'. diff --git a/tests/baselines/reference/parser.numericSeparators.binaryNegative.errors.txt b/tests/baselines/reference/parser.numericSeparators.binaryNegative.errors.txt index 15e08088b1e..bff028ba704 100644 --- a/tests/baselines/reference/parser.numericSeparators.binaryNegative.errors.txt +++ b/tests/baselines/reference/parser.numericSeparators.binaryNegative.errors.txt @@ -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 TS1005: ';' expected. +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 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 TS1005: ';' expected. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~ !!! error TS2304: Cannot find name 'B0101'. diff --git a/tests/baselines/reference/parser.numericSeparators.hexNegative.errors.txt b/tests/baselines/reference/parser.numericSeparators.hexNegative.errors.txt index 2fe62bc06d3..3aca519e572 100644 --- a/tests/baselines/reference/parser.numericSeparators.hexNegative.errors.txt +++ b/tests/baselines/reference/parser.numericSeparators.hexNegative.errors.txt @@ -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 TS1005: ';' expected. +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 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 TS1005: ';' expected. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~ !!! error TS2304: Cannot find name 'X0101'. diff --git a/tests/baselines/reference/parser.numericSeparators.octalNegative.errors.txt b/tests/baselines/reference/parser.numericSeparators.octalNegative.errors.txt index e4c05472106..58c1363b7ba 100644 --- a/tests/baselines/reference/parser.numericSeparators.octalNegative.errors.txt +++ b/tests/baselines/reference/parser.numericSeparators.octalNegative.errors.txt @@ -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 TS1005: ';' expected. +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 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 TS1005: ';' expected. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~~ !!! error TS2304: Cannot find name 'O0101'. diff --git a/tests/baselines/reference/tsxAttributeInvalidNames.errors.txt b/tests/baselines/reference/tsxAttributeInvalidNames.errors.txt index e83b588ef76..65b2fc23803 100644 --- a/tests/baselines/reference/tsxAttributeInvalidNames.errors.txt +++ b/tests/baselines/reference/tsxAttributeInvalidNames.errors.txt @@ -1,4 +1,5 @@ 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 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. @@ -12,7 +13,7 @@ tests/cases/conformance/jsx/file.tsx(11,13): error TS1005: ';' expected. tests/cases/conformance/jsx/file.tsx(11,20): error TS1161: Unterminated regular expression literal. -==== tests/cases/conformance/jsx/file.tsx (12 errors) ==== +==== tests/cases/conformance/jsx/file.tsx (13 errors) ==== declare module JSX { interface Element { } interface IntrinsicElements { @@ -25,6 +26,8 @@ tests/cases/conformance/jsx/file.tsx(11,20): error TS1161: Unterminated regular ; ~~ !!! error TS1003: Identifier expected. + ~ +!!! error TS1351: An identifier cannot follow a numeric literal. ~~~~ !!! error TS1005: ';' expected. ~~~~ diff --git a/tests/cases/compiler/identifierStartAfterNumericLiteral.ts b/tests/cases/compiler/identifierStartAfterNumericLiteral.ts new file mode 100644 index 00000000000..80e4760e11b --- /dev/null +++ b/tests/cases/compiler/identifierStartAfterNumericLiteral.ts @@ -0,0 +1,13 @@ +let valueIn = 3in[null]; + +3a[null] +3e[null] +3in[null] +3en[null] +1a +1e +1e9 +1ee +1n +2n2 +2na