8000 BigInt support by calebsander · Pull Request #25886 · microsoft/TypeScript · GitHub
[go: up one dir, main page]

Skip to content

BigInt support #25886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Nov 5, 2018
Merged
Prev Previous commit
Don't error on bigint literal used in type
  • Loading branch information
calebsander committed Nov 5, 2018
commit bb99c4123003ade3e471cf17472be6d3f72d96ff
16 changes: 10 additions & 6 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 4 additions & 2 deletions tests/baselines/reference/warnExperimentalBigIntLiteral.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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))

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, 3, 5))
>bigintNumber : Symbol(bigintNumber, Decl(warnExperimentalBigIntLiteral.ts, 4, 5))

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/cases/compiler/warnExperimentalBigIntLiteral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
0