Skip to content

Commit

Permalink
add action for enabling experimentalDescorators option in user config… (
Browse files Browse the repository at this point in the history
#30484)

* add action for enabling experimentalDescorators option in user config file, change error message for this case #29035

* add missing changes in tests

* Add "experimental decorators" tests for jsconfig file
  • Loading branch information
amaksimovich2 authored and RyanCavanaugh committed Apr 25, 2019
1 parent b8e3c41 commit 5b79b94
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Expand Up @@ -25636,7 +25636,7 @@ namespace ts {
}

if (!compilerOptions.experimentalDecorators) {
error(node, Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_to_remove_this_warning);
error(node, Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_in_your_tsconfig_or_jsconfig_to_remove_this_warning);
}

const firstDecorator = node.decorators[0];
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/diagnosticMessages.json
Expand Up @@ -691,7 +691,7 @@
"category": "Error",
"code": 1218
},
"Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.": {
"Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.": {
"category": "Error",
"code": 1219
},
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/program.ts
Expand Up @@ -1816,7 +1816,7 @@ namespace ts {

function walkArray(nodes: NodeArray<Node>) {
if (parent.decorators === nodes && !options.experimentalDecorators) {
diagnostics.push(createDiagnosticForNode(parent, Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_to_remove_this_warning));
diagnostics.push(createDiagnosticForNode(parent, Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_in_your_tsconfig_or_jsconfig_to_remove_this_warning));
}

switch (parent.kind) {
Expand Down
13 changes: 10 additions & 3 deletions src/services/codefixes/fixEnableExperimentalDecorators.ts
Expand Up @@ -2,7 +2,7 @@
namespace ts.codefix {
const fixId = "enableExperimentalDecorators";
const errorCodes = [
Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_to_remove_this_warning.code
Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_in_your_tsconfig_or_jsconfig_to_remove_this_warning.code
];
registerCodeFix({
errorCodes,
Expand All @@ -12,13 +12,20 @@ namespace ts.codefix {
return undefined;
}

const changes = textChanges.ChangeTracker.with(context, changeTracker => makeChange(changeTracker, configFile));
const changes = textChanges.ChangeTracker.with(context, changeTracker => doChange(changeTracker, configFile));
return [createCodeFixActionNoFixId(fixId, changes, Diagnostics.Enable_the_experimentalDecorators_option_in_your_configuration_file)];
},
fixIds: [fixId],
getAllCodeActions: context => codeFixAll(context, errorCodes, (changes) => {
const { configFile } = context.program.getCompilerOptions();
if (configFile === undefined) {
return undefined;
}
doChange(changes, configFile);
}),
});

function makeChange(changeTracker: textChanges.ChangeTracker, configFile: TsConfigSourceFile) {
function doChange(changeTracker: textChanges.ChangeTracker, configFile: TsConfigSourceFile) {
setJsonCompilerOptionValue(changeTracker, configFile, "experimentalDecorators", createTrue());
}
}
4 changes: 2 additions & 2 deletions tests/baselines/reference/decoratorInJsFile1.errors.txt
@@ -1,12 +1,12 @@
tests/cases/compiler/a.js(2,7): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
tests/cases/compiler/a.js(2,7): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.
tests/cases/compiler/a.js(3,12): error TS8010: 'types' can only be used in a .ts file.


==== tests/cases/compiler/a.js (2 errors) ====
@SomeDecorator
class SomeClass {
~~~~~~~~~
!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.
foo(x: number) {
~~~~~~
!!! error TS8010: 'types' can only be used in a .ts file.
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/generatorTypeCheck39.errors.txt
@@ -1,5 +1,5 @@
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(5,16): error TS1163: A 'yield' expression is only allowed in a generator body.
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(6,11): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(6,11): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(7,13): error TS1163: A 'yield' expression is only allowed in a generator body.


Expand All @@ -13,7 +13,7 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(7,13): erro
!!! error TS1163: A 'yield' expression is only allowed in a generator body.
class C {
~
!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.
x = yield 0;
~~~~~
!!! error TS1163: A 'yield' expression is only allowed in a generator body.
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/generatorTypeCheck59.errors.txt
@@ -1,5 +1,5 @@
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts(3,11): error TS1163: A 'yield' expression is only allowed in a generator body.
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts(4,9): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts(4,9): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.


==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts (2 errors) ====
Expand All @@ -10,6 +10,6 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts(4,9): error
!!! error TS1163: A 'yield' expression is only allowed in a generator body.
m() { }
~
!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.
};
}
4 changes: 2 additions & 2 deletions tests/baselines/reference/generatorTypeCheck61.errors.txt
@@ -1,5 +1,5 @@
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts(2,7): error TS1163: A 'yield' expression is only allowed in a generator body.
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts(3,11): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts(3,11): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.


==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts (2 errors) ====
Expand All @@ -9,5 +9,5 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts(3,11): erro
!!! error TS1163: A 'yield' expression is only allowed in a generator body.
class C {};
~
!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.
}
@@ -0,0 +1,26 @@
/// <reference path='fourslash.ts' />

// @Filename: /dir/a.ts
////declare const decorator: any;
////class A {
//// @decorator method() {};
////};

// @Filename: /dir/jsconfig.json
////{
//// "compilerOptions": {
//// }
////}

goTo.file("/dir/a.ts");
verify.codeFix({
description: "Enable the 'experimentalDecorators' option in your configuration file",
newFileContent: {
"/dir/jsconfig.json":
`{
"compilerOptions": {
"experimentalDecorators": true,
}
}`,
},
});
@@ -0,0 +1,27 @@
/// <reference path='fourslash.ts' />

// @Filename: /dir/a.ts
////declare const decorator: any;
////class A {
//// @decorator method() {};
////};

// @Filename: /dir/jsconfig.json
////{
//// "compilerOptions": {
//// "experimentalDecorators": false,
//// }
////}

goTo.file("/dir/a.ts");
verify.codeFix({
description: "Enable the 'experimentalDecorators' option in your configuration file",
newFileContent: {
"/dir/jsconfig.json":
`{
"compilerOptions": {
"experimentalDecorators": true,
}
}`,
},
});
@@ -0,0 +1,22 @@
/// <reference path='fourslash.ts' />

// @Filename: /dir/a.ts
////declare const decorator: any;
////class A {
//// @decorator method() {};
////};

// @Filename: /dir/jsconfig.json
////{
////}

goTo.file("/dir/a.ts");
verify.codeFix({
description: "Enable the 'experimentalDecorators' option in your configuration file",
newFileContent: {
"/dir/jsconfig.json":
`{
"compilerOptions": { "experimentalDecorators": true },
}`,
},
});

0 comments on commit 5b79b94

Please sign in to comment.