From 3a96b18910c0d54a26fa42c41bcadca20a30591a Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 27 Sep 2017 14:22:11 -0400 Subject: [PATCH] Adds an --experimentalThrowExpressions flag --- src/compiler/checker.ts | 4 ++++ src/compiler/commandLineParser.ts | 6 ++++++ src/compiler/diagnosticMessages.json | 9 +++++++++ src/compiler/types.ts | 1 + .../throwExpressions/throwExpressions.es2015.ts | 1 + .../throwExpressions/throwExpressions.esnext.ts | 1 + 6 files changed, 22 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index db8b0a542e5..7430faa7197 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -17179,6 +17179,10 @@ namespace ts { } function checkThrowExpression(node: ThrowExpression): Type { + if (!compilerOptions.experimentalThrowExpressions) { + error(node, Diagnostics.Experimental_support_for_throw_expressions_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalThrowExpressions_option_to_remove_this_warning); + } + checkExpression(node.expression); return neverType; } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 54e5ee1d01d..c7f8d141d06 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -433,6 +433,12 @@ namespace ts { category: Diagnostics.Experimental_Options, description: Diagnostics.Enables_experimental_support_for_emitting_type_metadata_for_decorators }, + { + name: "experimentalThrowExpressions", + type: "boolean", + category: Diagnostics.Experimental_Options, + description: Diagnostics.Enables_experimental_support_for_ECMAScript_Stage_2_throw_expressions + }, // Advanced { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 9c0b549da50..d23348c3bd0 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -907,6 +907,10 @@ "category": "Error", "code": 1328 }, + "Experimental support for 'throw' expressions is a feature that is subject to change in a future release. Set the 'experimentalThrowExpressions' option to remove this warning.": { + "category": "Error", + "code": 1329 + }, "Duplicate identifier '{0}'.": { "category": "Error", @@ -3314,6 +3318,11 @@ "category": "Message", "code": 6185 }, + "Enables experimental support for ECMAScript Stage-2 'throw' expressions.": { + "category": "Message", + "code": 6186 + }, + "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", "code": 7005 diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 48241efb04a..6d9dbaa0764 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3658,6 +3658,7 @@ namespace ts { emitBOM?: boolean; emitDecoratorMetadata?: boolean; experimentalDecorators?: boolean; + experimentalThrowExpressions?: boolean; forceConsistentCasingInFileNames?: boolean; /*@internal*/help?: boolean; importHelpers?: boolean; diff --git a/tests/cases/conformance/expressions/throwExpressions/throwExpressions.es2015.ts b/tests/cases/conformance/expressions/throwExpressions/throwExpressions.es2015.ts index fc665db0b03..4a25d78965d 100644 --- a/tests/cases/conformance/expressions/throwExpressions/throwExpressions.es2015.ts +++ b/tests/cases/conformance/expressions/throwExpressions/throwExpressions.es2015.ts @@ -1,4 +1,5 @@ // @target: es2015 +// @experimentalThrowExpressions: true declare const condition: boolean; const a = condition ? 1 : throw new Error(); const b = condition || throw new Error(); diff --git a/tests/cases/conformance/expressions/throwExpressions/throwExpressions.esnext.ts b/tests/cases/conformance/expressions/throwExpressions/throwExpressions.esnext.ts index 2a41f11e19f..f34f6ff85a4 100644 --- a/tests/cases/conformance/expressions/throwExpressions/throwExpressions.esnext.ts +++ b/tests/cases/conformance/expressions/throwExpressions/throwExpressions.esnext.ts @@ -1,4 +1,5 @@ // @target: esnext +// @experimentalThrowExpressions: true declare const condition: boolean; const a = condition ? 1 : throw new Error(); const b = condition || throw new Error();