From 95c24c6c6ab0898d906f2f798258aa332dd8b582 Mon Sep 17 00:00:00 2001 From: Caleb Sander Date: Sat, 29 Sep 2018 15:12:17 -0700 Subject: [PATCH] experimentalBigInt compiler flag --- src/compiler/checker.ts | 3 +++ src/compiler/commandLineParser.ts | 6 ++++++ src/compiler/types.ts | 1 + .../reference/api/tsserverlibrary.d.ts | 1 + tests/baselines/reference/api/typescript.d.ts | 1 + .../Default initialized TSConfig/tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../tsconfig.json | 1 + .../warnExperimentalBigIntLiteral.errors.txt | 17 +++++++++++++++++ .../reference/warnExperimentalBigIntLiteral.js | 7 +++++++ .../warnExperimentalBigIntLiteral.symbols | 7 +++++++ .../warnExperimentalBigIntLiteral.types | 15 +++++++++++++++ .../compiler/warnExperimentalBigIntLiteral.ts | 2 ++ 19 files changed, 69 insertions(+) create mode 100644 tests/baselines/reference/warnExperimentalBigIntLiteral.errors.txt create mode 100644 tests/baselines/reference/warnExperimentalBigIntLiteral.js create mode 100644 tests/baselines/reference/warnExperimentalBigIntLiteral.symbols create mode 100644 tests/baselines/reference/warnExperimentalBigIntLiteral.types create mode 100644 tests/cases/compiler/warnExperimentalBigIntLiteral.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5e03f1b3987..0353b21869d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9270,6 +9270,9 @@ namespace ts { function getNumericLiteralValue(node: NumericLiteral): number | PseudoBigInt { if (node.numericLiteralFlags & TokenFlags.BigInt) { + if (!compilerOptions.experimentalBigInt) { + error(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 { negative: false, base10Value: parsePseudoBigInt(node.text) }; } return +node.text; diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index cbd6188ff66..9c333f2cadf 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -584,6 +584,12 @@ namespace ts { category: Diagnostics.Experimental_Options, description: Diagnostics.Enables_experimental_support_for_emitting_type_metadata_for_decorators }, + { + name: "experimentalBigInt", + type: "boolean", + category: Diagnostics.Experimental_Options, + description: Diagnostics.Enables_experimental_support_for_ESNext_BigInt_expressions + }, // Advanced { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9d696e3a8d0..9607b95b8e3 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4499,6 +4499,7 @@ namespace ts { downlevelIteration?: boolean; emitBOM?: boolean; emitDecoratorMetadata?: boolean; + experimentalBigInt?: boolean; experimentalDecorators?: boolean; forceConsistentCasingInFileNames?: boolean; /*@internal*/help?: boolean; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 62577f6c747..68113b99ca1 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2458,6 +2458,7 @@ declare namespace ts { downlevelIteration?: boolean; emitBOM?: boolean; emitDecoratorMetadata?: boolean; + experimentalBigInt?: boolean; experimentalDecorators?: boolean; forceConsistentCasingInFileNames?: boolean; importHelpers?: boolean; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 875a293fee2..fee1057fd2d 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2458,6 +2458,7 @@ declare namespace ts { downlevelIteration?: boolean; emitBOM?: boolean; emitDecoratorMetadata?: boolean; + experimentalBigInt?: boolean; experimentalDecorators?: boolean; forceConsistentCasingInFileNames?: boolean; importHelpers?: boolean; diff --git a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json index e4e3d7b8ec4..778fb9572f4 100644 --- a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json @@ -56,5 +56,6 @@ /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt expressions. */ } } \ No newline at end of file diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json index 1919671c489..16462f9d660 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json @@ -56,6 +56,7 @@ /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt expressions. */ /* Advanced Options */ "noErrorTruncation": true, /* Do not truncate error messages. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json index 3b49dee6e3d..fa8e2c70a66 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json @@ -56,5 +56,6 @@ /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt expressions. */ } } \ No newline at end of file diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json index d91e167877d..2d2d84b100c 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json @@ -56,5 +56,6 @@ /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt expressions. */ } } \ No newline at end of file diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json index e6107b29b4c..68329ceecb5 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json @@ -56,6 +56,7 @@ /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt expressions. */ }, "files": [ "file0.st", diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json index 7c18b695c7b..eb13052b37c 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json @@ -56,5 +56,6 @@ /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt expressions. */ } } \ No newline at end of file diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json index e4e3d7b8ec4..778fb9572f4 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json @@ -56,5 +56,6 @@ /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt expressions. */ } } \ No newline at end of file diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json index eedcc357043..c9afe008935 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json @@ -56,5 +56,6 @@ /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt expressions. */ } } \ No newline at end of file diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json index 6fc7833730f..37444c9a5de 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json @@ -56,5 +56,6 @@ /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + // "experimentalBigInt": true, /* Enables experimental support for ESNext BigInt expressions. */ } } \ No newline at end of file diff --git a/tests/baselines/reference/warnExperimentalBigIntLiteral.errors.txt b/tests/baselines/reference/warnExperimentalBigIntLiteral.errors.txt new file mode 100644 index 00000000000..8a1207f4510 --- /dev/null +++ b/tests/baselines/reference/warnExperimentalBigIntLiteral.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/warnExperimentalBigIntLiteral.ts(2,22): error TS1350: 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(2,29): error TS1350: 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(2,39): error TS1350: 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(2,48): error TS1350: 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 errors) ==== + const normalNumber = 123; // should not error + const bigintNumber = 123n * 0b1111n + 0o444n * 0x7fn; // each literal should error + ~~~~ +!!! error TS1350: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning. + ~~~~~~~ +!!! error TS1350: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning. + ~~~~~~ +!!! error TS1350: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning. + ~~~~~ +!!! error TS1350: Experimental support for BigInt is a feature that is subject to change in a future release. Set the 'experimentalBigInt' option to remove this warning. \ No newline at end of file diff --git a/tests/baselines/reference/warnExperimentalBigIntLiteral.js b/tests/baselines/reference/warnExperimentalBigIntLiteral.js new file mode 100644 index 00000000000..3f856417130 --- /dev/null +++ b/tests/baselines/reference/warnExperimentalBigIntLiteral.js @@ -0,0 +1,7 @@ +//// [warnExperimentalBigIntLiteral.ts] +const normalNumber = 123; // should not error +const bigintNumber = 123n * 0b1111n + 0o444n * 0x7fn; // each literal should error + +//// [warnExperimentalBigIntLiteral.js] +var normalNumber = 123; // should not error +var bigintNumber = 123n * 15n + 292n * 0x7fn; // each literal should error diff --git a/tests/baselines/reference/warnExperimentalBigIntLiteral.symbols b/tests/baselines/reference/warnExperimentalBigIntLiteral.symbols new file mode 100644 index 00000000000..a54991a7bd5 --- /dev/null +++ b/tests/baselines/reference/warnExperimentalBigIntLiteral.symbols @@ -0,0 +1,7 @@ +=== tests/cases/compiler/warnExperimentalBigIntLiteral.ts === +const normalNumber = 123; // should not error +>normalNumber : Symbol(normalNumber, Decl(warnExperimentalBigIntLiteral.ts, 0, 5)) + +const bigintNumber = 123n * 0b1111n + 0o444n * 0x7fn; // each literal should error +>bigintNumber : Symbol(bigintNumber, Decl(warnExperimentalBigIntLiteral.ts, 1, 5)) + diff --git a/tests/baselines/reference/warnExperimentalBigIntLiteral.types b/tests/baselines/reference/warnExperimentalBigIntLiteral.types new file mode 100644 index 00000000000..1a15f5d5dae --- /dev/null +++ b/tests/baselines/reference/warnExperimentalBigIntLiteral.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/warnExperimentalBigIntLiteral.ts === +const normalNumber = 123; // should not error +>normalNumber : 123 +>123 : 123 + +const bigintNumber = 123n * 0b1111n + 0o444n * 0x7fn; // each literal should error +>bigintNumber : bigint +>123n * 0b1111n + 0o444n * 0x7fn : bigint +>123n * 0b1111n : bigint +>123n : 123n +>0b1111n : 15n +>0o444n * 0x7fn : bigint +>0o444n : 292n +>0x7fn : 127n + diff --git a/tests/cases/compiler/warnExperimentalBigIntLiteral.ts b/tests/cases/compiler/warnExperimentalBigIntLiteral.ts new file mode 100644 index 00000000000..f837a17f7a1 --- /dev/null +++ b/tests/cases/compiler/warnExperimentalBigIntLiteral.ts @@ -0,0 +1,2 @@ +const normalNumber = 123; // should not error +const bigintNumber = 123n * 0b1111n + 0o444n * 0x7fn; // each literal should error \ No newline at end of file