Don't error on bigint literal used in type

This commit is contained in:
Caleb Sander 2018-11-05 12:23:02 -08:00
parent 6c59a3b890
commit bb99c41230
6 changed files with 35 additions and 22 deletions

View File

@ -30471,13 +30471,17 @@ namespace ts {
}
function checkGrammarBigIntLiteral(node: BigIntLiteral): boolean {
if (languageVersion < ScriptTarget.ESNext) {
if (grammarErrorOnNode(node, Diagnostics.BigInt_literals_are_not_available_when_targetting_lower_than_ESNext)) {
return true;
const literalType = isLiteralTypeNode(node.parent) ||
isPrefixUnaryExpression(node.parent) && isLiteralTypeNode(node.parent.parent);
if (!literalType) {
if (languageVersion < ScriptTarget.ESNext) {
if (grammarErrorOnNode(node, Diagnostics.BigInt_literals_are_not_available_when_targetting_lower_than_ESNext)) {
return true;
}
}
if (!compilerOptions.experimentalBigInt) {
return grammarErrorOnNode(node, Diagnostics.Experimental_support_for_BigInt_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalBigInt_option_to_remove_this_warning);
}
}
if (!compilerOptions.experimentalBigInt) {
return grammarErrorOnNode(node, Diagnostics.Experimental_support_for_BigInt_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalBigInt_option_to_remove_this_warning);
}
return false;
}

View File

@ -1,16 +1,14 @@
tests/cases/compiler/warnExperimentalBigIntLiteral.ts(3,24): error TS1351: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
tests/cases/compiler/warnExperimentalBigIntLiteral.ts(4,22): error TS1351: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
tests/cases/compiler/warnExperimentalBigIntLiteral.ts(4,29): error TS1351: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
tests/cases/compiler/warnExperimentalBigIntLiteral.ts(4,39): error TS1351: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
tests/cases/compiler/warnExperimentalBigIntLiteral.ts(4,48): error TS1351: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
tests/cases/compiler/warnExperimentalBigIntLiteral.ts(5,22): error TS1351: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
tests/cases/compiler/warnExperimentalBigIntLiteral.ts(5,29): error TS1351: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
tests/cases/compiler/warnExperimentalBigIntLiteral.ts(5,39): error TS1351: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
tests/cases/compiler/warnExperimentalBigIntLiteral.ts(5,48): error TS1351: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
==== tests/cases/compiler/warnExperimentalBigIntLiteral.ts (5 errors) ====
==== tests/cases/compiler/warnExperimentalBigIntLiteral.ts (4 errors) ====
const normalNumber = 123; // should not error
let bigintType: bigint; // should not error
let bigintLiteralType: 123n; // should error when used as type
~~~~
!!! error TS1351: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.
let bigintLiteralType: 123n; // should not error when used as type
let bigintNegativeLiteralType: -123n; // should not error when used as type
const bigintNumber = 123n * 0b1111n + 0o444n * 0x7fn; // each literal should error
~~~~
!!! error TS1351: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning.

View File

@ -1,11 +1,13 @@
//// [warnExperimentalBigIntLiteral.ts]
const normalNumber = 123; // should not error
let bigintType: bigint; // should not error
let bigintLiteralType: 123n; // should error when used as type
let bigintLiteralType: 123n; // should not error when used as type
let bigintNegativeLiteralType: -123n; // should not error when used as type
const bigintNumber = 123n * 0b1111n + 0o444n * 0x7fn; // each literal should error
//// [warnExperimentalBigIntLiteral.js]
const normalNumber = 123; // should not error
let bigintType; // should not error
let bigintLiteralType; // should error when used as type
let bigintLiteralType; // should not error when used as type
let bigintNegativeLiteralType; // should not error when used as type
const bigintNumber = 123n * 15n + 292n * 0x7fn; // each literal should error

View File

@ -5,9 +5,12 @@ const normalNumber = 123; // should not error
let bigintType: bigint; // should not error
>bigintType : Symbol(bigintType, Decl(warnExperimentalBigIntLiteral.ts, 1, 3))
let bigintLiteralType: 123n; // should error when used as type
let bigintLiteralType: 123n; // should not error when used as type
>bigintLiteralType : Symbol(bigintLiteralType, Decl(warnExperimentalBigIntLiteral.ts, 2, 3))
const bigintNumber = 123n * 0b1111n + 0o444n * 0x7fn; // each literal should error
>bigintNumber : Symbol(bigintNumber, Decl(warnExperimentalBigIntLiteral.ts, 3, 5))
let bigintNegativeLiteralType: -123n; // should not error when used as type
>bigintNegativeLiteralType : Symbol(bigintNegativeLiteralType, Decl(warnExperimentalBigIntLiteral.ts, 3, 3))
const bigintNumber = 123n * 0b1111n + 0o444n * 0x7fn; // each literal should error
>bigintNumber : Symbol(bigintNumber, Decl(warnExperimentalBigIntLiteral.ts, 4, 5))

View File

@ -6,9 +6,14 @@ const normalNumber = 123; // should not error
let bigintType: bigint; // should not error
>bigintType : bigint
let bigintLiteralType: 123n; // should error when used as type
let bigintLiteralType: 123n; // should not error when used as type
>bigintLiteralType : 123n
let bigintNegativeLiteralType: -123n; // should not error when used as type
>bigintNegativeLiteralType : -123n
>-123n : -123n
>123n : 123n
const bigintNumber = 123n * 0b1111n + 0o444n * 0x7fn; // each literal should error
>bigintNumber : bigint
>123n * 0b1111n + 0o444n * 0x7fn : bigint

View File

@ -2,5 +2,6 @@
const normalNumber = 123; // should not error
let bigintType: bigint; // should not error
let bigintLiteralType: 123n; // should error when used as type
let bigintLiteralType: 123n; // should not error when used as type
let bigintNegativeLiteralType: -123n; // should not error when used as type
const bigintNumber = 123n * 0b1111n + 0o444n * 0x7fn; // each literal should error