From 174816fc2608adece8fd1f831bb3b9054e22835d Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 4 Dec 2018 17:59:20 -0800 Subject: [PATCH 1/4] Added error for IdentifierStart immediately after a NumericLiteral Fixes #4702. --- src/compiler/diagnosticMessages.json | 4 + src/compiler/scanner.ts | 10 + .../reference/bigIntWithTargetES3.errors.txt | 23 +- .../reference/bigintIndex.errors.txt | 22 +- .../reference/bigintWithLib.errors.txt | 49 +++- .../reference/bigintWithoutLib.errors.txt | 68 +++-- ...ntifierStartAfterNumericLiteral.errors.txt | 74 +++++ .../identifierStartAfterNumericLiteral.js | 35 +++ ...identifierStartAfterNumericLiteral.symbols | 16 ++ .../identifierStartAfterNumericLiteral.types | 56 ++++ .../numberVsBigIntOperations.errors.txt | 254 +++++++++++++++++- ...ralsWithTrailingDecimalPoints01.errors.txt | 12 +- .../reference/parseBigInt.errors.txt | 71 ++++- ...umericSeparators.binaryNegative.errors.txt | 6 +- ...r.numericSeparators.hexNegative.errors.txt | 6 +- ...numericSeparators.octalNegative.errors.txt | 6 +- .../tsxAttributeInvalidNames.errors.txt | 5 +- .../identifierStartAfterNumericLiteral.ts | 13 + 18 files changed, 643 insertions(+), 87 deletions(-) create mode 100644 tests/baselines/reference/identifierStartAfterNumericLiteral.errors.txt create mode 100644 tests/baselines/reference/identifierStartAfterNumericLiteral.js create mode 100644 tests/baselines/reference/identifierStartAfterNumericLiteral.symbols create mode 100644 tests/baselines/reference/identifierStartAfterNumericLiteral.types create mode 100644 tests/cases/compiler/identifierStartAfterNumericLiteral.ts diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e3f8e1a7ad5a6..b7aaaf0274287 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 9eedfeefb53ff..3762eaa91fa7d 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 6fa938535f11d..ed65939999a62 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 50e360a190589..628e2b683be30 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 993f43d5a055f..7ae0be26a2185 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 7d2c38b29df56..3210ce580424d 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 0000000000000..03e408a6486a3 --- /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 0000000000000..0ec84716c2cad --- /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 0000000000000..71b253dbecc73 --- /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 0000000000000..b31c9ee8d11e0 --- /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 fbd49ddd091e1..7f97bcc78a62a 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 ca85c992fa488..42561707d563a 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 9c273542c0b78..df4d9dce4aa70 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 15e08088b1ef6..bff028ba704c6 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 2fe62bc06d3d9..3aca519e5729d 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 e4c054721060e..58c1363b7baaa 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 e83b588ef76cb..65b2fc2380321 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 0000000000000..80e4760e11b2b --- /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 From 51d10ee4a0acc3afbb8815cdf4e5fcac312c8c6b Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 4 Dec 2018 18:29:58 -0800 Subject: [PATCH 2/4] Removed excess new check --- src/compiler/scanner.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 3762eaa91fa7d..1589cca8357b2 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -975,9 +975,8 @@ namespace ts { result = text.substring(start, end); // No need to use all the fragments; no _ removal needed } - checkForIdentifierAfterNumericLiteral(); if (decimalFragment !== undefined || tokenFlags & TokenFlags.Scientific) { - checkForIdentifierAfterNumericLiteral(); + checkForIdentifierStartAfterNumericLiteral(); return { type: SyntaxKind.NumericLiteral, value: "" + +result // if value is not an integer, it can be safely coerced to a number @@ -986,12 +985,12 @@ namespace ts { else { tokenValue = result; const type = checkBigIntSuffix(); // if value is an integer, check whether it is a bigint - checkForIdentifierAfterNumericLiteral(); + checkForIdentifierStartAfterNumericLiteral(); return { type, value: tokenValue }; } } - function checkForIdentifierAfterNumericLiteral() { + function checkForIdentifierStartAfterNumericLiteral() { if (isIdentifierStart(text.charCodeAt(pos), languageVersion)) { error(Diagnostics.An_identifier_cannot_follow_a_numeric_literal, pos, 1); } From 31fca3af4d432112516d699163456fc070a590f8 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 4 Dec 2018 18:33:06 -0800 Subject: [PATCH 3/4] Accepted new baselines --- .../reference/bigIntWithTargetES3.errors.txt | 23 +- .../reference/bigintIndex.errors.txt | 22 +- .../reference/bigintWithLib.errors.txt | 49 +--- .../reference/bigintWithoutLib.errors.txt | 68 ++--- ...ntifierStartAfterNumericLiteral.errors.txt | 11 +- .../numberVsBigIntOperations.errors.txt | 254 +----------------- .../reference/parseBigInt.errors.txt | 59 +--- 7 files changed, 66 insertions(+), 420 deletions(-) diff --git a/tests/baselines/reference/bigIntWithTargetES3.errors.txt b/tests/baselines/reference/bigIntWithTargetES3.errors.txt index ed65939999a62..6fa938535f11d 100644 --- a/tests/baselines/reference/bigIntWithTargetES3.errors.txt +++ b/tests/baselines/reference/bigIntWithTargetES3.errors.txt @@ -1,18 +1,21 @@ -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(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 errors) ==== +==== tests/cases/compiler/bigIntWithTargetES3.ts (4 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 TS1351: An identifier cannot follow a numeric literal. + ~~~~ +!!! 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. \ No newline at end of file diff --git a/tests/baselines/reference/bigintIndex.errors.txt b/tests/baselines/reference/bigintIndex.errors.txt index 628e2b683be30..50e360a190589 100644 --- a/tests/baselines/reference/bigintIndex.errors.txt +++ b/tests/baselines/reference/bigintIndex.errors.txt @@ -1,21 +1,19 @@ +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 (6 errors) ==== +==== tests/cases/compiler/a.ts (4 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]; @@ -24,8 +22,6 @@ 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; @@ -34,13 +30,9 @@ 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 ~~~~~~ @@ -50,13 +42,11 @@ 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 (7 errors) ==== +==== tests/cases/compiler/b.ts (5 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. ~ @@ -64,8 +54,6 @@ 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 7ae0be26a2185..993f43d5a055f 100644 --- a/tests/baselines/reference/bigintWithLib.errors.txt +++ b/tests/baselines/reference/bigintWithLib.errors.txt @@ -1,30 +1,15 @@ 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 (22 errors) ==== +==== tests/cases/compiler/bigintWithLib.ts (7 errors) ==== // Test BigInt functions let bigintVal: bigint = BigInt(123); bigintVal = BigInt("456"); @@ -42,12 +27,6 @@ tests/cases/compiler/bigintWithLib.ts(53,11): error TS1351: An identifier cannot 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'. @@ -65,12 +44,6 @@ tests/cases/compiler/bigintWithLib.ts(53,11): error TS1351: An identifier cannot 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'. @@ -87,20 +60,12 @@ tests/cases/compiler/bigintWithLib.ts(53,11): error TS1351: An identifier cannot // 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'. @@ -111,16 +76,6 @@ tests/cases/compiler/bigintWithLib.ts(53,11): error TS1351: An identifier cannot // 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 - ~ -!!! 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 + let z = 12n; // should emit type bigint in declaration file \ No newline at end of file diff --git a/tests/baselines/reference/bigintWithoutLib.errors.txt b/tests/baselines/reference/bigintWithoutLib.errors.txt index 3210ce580424d..7d2c38b29df56 100644 --- a/tests/baselines/reference/bigintWithoutLib.errors.txt +++ b/tests/baselines/reference/bigintWithoutLib.errors.txt @@ -2,16 +2,18 @@ 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,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(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(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'. @@ -20,22 +22,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,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(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(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,27): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/bigintWithoutLib.ts(40,26): error TS2737: BigInt literals are not available when targeting lower than ESNext. tests/cases/compiler/bigintWithoutLib.ts(41,10): error TS2339: Property 'setBigInt64' does not exist on type 'DataView'. -tests/cases/compiler/bigintWithoutLib.ts(41,27): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/bigintWithoutLib.ts(41,26): error TS2737: BigInt literals are not available when targeting lower than ESNext. 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,29): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/bigintWithoutLib.ts(43,26): error TS2737: BigInt literals are not available when targeting lower than ESNext. tests/cases/compiler/bigintWithoutLib.ts(44,10): error TS2339: Property 'setBigUint64' does not exist on type 'DataView'. -tests/cases/compiler/bigintWithoutLib.ts(44,29): error TS1351: An identifier cannot follow a numeric literal. +tests/cases/compiler/bigintWithoutLib.ts(44,26): error TS2737: BigInt literals are not available when targeting lower than ESNext. 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'. @@ -43,7 +45,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 (43 errors) ==== +==== tests/cases/compiler/bigintWithoutLib.ts (45 errors) ==== // Every line should error because these builtins are not declared // Test BigInt functions @@ -59,9 +61,13 @@ 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'. @@ -86,12 +92,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 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 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. bigIntArray = new BigInt64Array([1, 2, 3]); ~~~~~~~~~~~~~ !!! error TS2552: Cannot find name 'BigInt64Array'. Did you mean 'bigIntArray'? @@ -121,12 +127,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 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 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. bigUintArray = new BigUint64Array([1, 2, 3]); ~~~~~~~~~~~~~~ !!! error TS2304: Cannot find name 'BigUint64Array'. @@ -148,26 +154,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 TS1351: An identifier cannot follow a numeric literal. + ~~ +!!! error TS2737: BigInt literals are not available when targeting lower than ESNext. dataView.setBigInt64(1, -1n, true); ~~~~~~~~~~~ !!! error TS2339: Property 'setBigInt64' does not exist on type 'DataView'. - ~ -!!! error TS1351: An identifier cannot follow a numeric literal. + ~~ +!!! error TS2737: BigInt literals are not available when targeting lower than ESNext. 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 TS1351: An identifier cannot follow a numeric literal. + ~~~~ +!!! error TS2737: BigInt literals are not available when targeting lower than ESNext. dataView.setBigUint64(2, 123n, true); ~~~~~~~~~~~~ !!! error TS2339: Property 'setBigUint64' does not exist on type 'DataView'. - ~ -!!! error TS1351: An identifier cannot follow a numeric literal. + ~~~~ +!!! error TS2737: BigInt literals are not available when targeting lower than ESNext. 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 index 03e408a6486a3..130e676d0d155 100644 --- a/tests/baselines/reference/identifierStartAfterNumericLiteral.errors.txt +++ b/tests/baselines/reference/identifierStartAfterNumericLiteral.errors.txt @@ -11,15 +11,12 @@ tests/cases/compiler/identifierStartAfterNumericLiteral.ts(7,2): error TS2304: C 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) ==== +==== tests/cases/compiler/identifierStartAfterNumericLiteral.ts (16 errors) ==== let valueIn = 3in[null]; ~ !!! error TS1351: An identifier cannot follow a numeric literal. @@ -57,16 +54,10 @@ tests/cases/compiler/identifierStartAfterNumericLiteral.ts(13,3): error TS2304: ~ !!! 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. ~ diff --git a/tests/baselines/reference/numberVsBigIntOperations.errors.txt b/tests/baselines/reference/numberVsBigIntOperations.errors.txt index 7f97bcc78a62a..fbd49ddd091e1 100644 --- a/tests/baselines/reference/numberVsBigIntOperations.errors.txt +++ b/tests/baselines/reference/numberVsBigIntOperations.errors.txt @@ -1,124 +1,51 @@ -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. @@ -128,286 +55,137 @@ 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(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(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 (144 errors) ==== +==== tests/cases/compiler/numberVsBigIntOperations.ts (64 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; @@ -419,13 +197,9 @@ tests/cases/compiler/numberVsBigIntOperations.ts(93,22): error TS1351: An identi 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'. @@ -462,12 +236,8 @@ tests/cases/compiler/numberVsBigIntOperations.ts(93,22): error TS1351: An identi !!! 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 @@ -503,27 +273,17 @@ tests/cases/compiler/numberVsBigIntOperations.ts(93,22): error TS1351: An identi // 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 TS1351: An identifier cannot follow a numeric literal. + ~~~~~~~~~~~~ +!!! error TS1155: 'const' declarations must be initialized. 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 TS1351: An identifier cannot follow a numeric literal. + ~~~~~~~~~~~~ +!!! error TS1155: 'const' declarations must be initialized. if (bigZeroOrOne) isOne(bigZeroOrOne); \ No newline at end of file diff --git a/tests/baselines/reference/parseBigInt.errors.txt b/tests/baselines/reference/parseBigInt.errors.txt index df4d9dce4aa70..77d8b55ed9811 100644 --- a/tests/baselines/reference/parseBigInt.errors.txt +++ b/tests/baselines/reference/parseBigInt.errors.txt @@ -1,13 +1,4 @@ -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 TS1351: An identifier cannot follow a numeric literal. @@ -18,48 +9,32 @@ 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 (36 errors) ==== +==== tests/cases/compiler/parseBigInt.ts (17 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 @@ -85,29 +60,17 @@ 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'. @@ -141,35 +104,15 @@ 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'. From a2111843479cbae191eac29b58fd016069fc53e2 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Thu, 6 Dec 2018 11:17:06 -0800 Subject: [PATCH 4/4] 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. --- src/compiler/diagnosticMessages.json | 2 +- src/compiler/scanner.ts | 9 +- ...ntifierStartAfterNumericLiteral.errors.txt | 116 ++++++++++++++---- .../identifierStartAfterNumericLiteral.js | 34 +++++ ...identifierStartAfterNumericLiteral.symbols | 13 ++ .../identifierStartAfterNumericLiteral.types | 56 +++++++++ ...ralsWithTrailingDecimalPoints01.errors.txt | 12 +- .../reference/parseBigInt.errors.txt | 12 +- ...umericSeparators.binaryNegative.errors.txt | 6 +- ...r.numericSeparators.hexNegative.errors.txt | 6 +- ...numericSeparators.octalNegative.errors.txt | 6 +- .../tsxAttributeInvalidNames.errors.txt | 6 +- .../identifierStartAfterNumericLiteral.ts | 13 ++ 13 files changed, 241 insertions(+), 50 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b7aaaf0274287..cde7516f04719 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -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 }, diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 1589cca8357b2..a9438110593a3 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -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 { diff --git a/tests/baselines/reference/identifierStartAfterNumericLiteral.errors.txt b/tests/baselines/reference/identifierStartAfterNumericLiteral.errors.txt index 130e676d0d155..2b4884f730328 100644 --- a/tests/baselines/reference/identifierStartAfterNumericLiteral.errors.txt +++ b/tests/baselines/reference/identifierStartAfterNumericLiteral.errors.txt @@ -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'. \ No newline at end of file diff --git a/tests/baselines/reference/identifierStartAfterNumericLiteral.js b/tests/baselines/reference/identifierStartAfterNumericLiteral.js index 0ec84716c2cad..59ece3e1c7e91 100644 --- a/tests/baselines/reference/identifierStartAfterNumericLiteral.js +++ b/tests/baselines/reference/identifierStartAfterNumericLiteral.js @@ -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; diff --git a/tests/baselines/reference/identifierStartAfterNumericLiteral.symbols b/tests/baselines/reference/identifierStartAfterNumericLiteral.symbols index 71b253dbecc73..8237191eee47a 100644 --- a/tests/baselines/reference/identifierStartAfterNumericLiteral.symbols +++ b/tests/baselines/reference/identifierStartAfterNumericLiteral.symbols @@ -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 diff --git a/tests/baselines/reference/identifierStartAfterNumericLiteral.types b/tests/baselines/reference/identifierStartAfterNumericLiteral.types index b31c9ee8d11e0..af3399a6d139a 100644 --- a/tests/baselines/reference/identifierStartAfterNumericLiteral.types +++ b/tests/baselines/reference/identifierStartAfterNumericLiteral.types @@ -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 + diff --git a/tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.errors.txt b/tests/baselines/reference/numericLiteralsWithTrailingDecimalPoints01.errors.txt index 42561707d563a..ac319184f8a71 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 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. ~ diff --git a/tests/baselines/reference/parseBigInt.errors.txt b/tests/baselines/reference/parseBigInt.errors.txt index 77d8b55ed9811..16878e75fe98f 100644 --- a/tests/baselines/reference/parseBigInt.errors.txt +++ b/tests/baselines/reference/parseBigInt.errors.txt @@ -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. diff --git a/tests/baselines/reference/parser.numericSeparators.binaryNegative.errors.txt b/tests/baselines/reference/parser.numericSeparators.binaryNegative.errors.txt index bff028ba704c6..93118bc9c7fb7 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 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'. diff --git a/tests/baselines/reference/parser.numericSeparators.hexNegative.errors.txt b/tests/baselines/reference/parser.numericSeparators.hexNegative.errors.txt index 3aca519e5729d..c6048a1bbfb4c 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 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'. diff --git a/tests/baselines/reference/parser.numericSeparators.octalNegative.errors.txt b/tests/baselines/reference/parser.numericSeparators.octalNegative.errors.txt index 58c1363b7baaa..ebdec3371aa64 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 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'. diff --git a/tests/baselines/reference/tsxAttributeInvalidNames.errors.txt b/tests/baselines/reference/tsxAttributeInvalidNames.errors.txt index 65b2fc2380321..d0b521d045494 100644 --- a/tests/baselines/reference/tsxAttributeInvalidNames.errors.txt +++ b/tests/baselines/reference/tsxAttributeInvalidNames.errors.txt @@ -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 ; ~~ !!! 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. diff --git a/tests/cases/compiler/identifierStartAfterNumericLiteral.ts b/tests/cases/compiler/identifierStartAfterNumericLiteral.ts index 80e4760e11b2b..14e5cca0e25b4 100644 --- a/tests/cases/compiler/identifierStartAfterNumericLiteral.ts +++ b/tests/cases/compiler/identifierStartAfterNumericLiteral.ts @@ -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