add action for enabling experimentalDescorators option in user config… (#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
This commit is contained in:
amaksimovich2
2019-04-25 14:55:04 -07:00
committed by Ryan Cavanaugh
parent b8e3c41ee1
commit 5b79b942e8
14 changed files with 96 additions and 14 deletions
+1 -1
View File
@@ -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];
+1 -1
View File
@@ -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
},
+1 -1
View File
@@ -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) {
@@ -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,
@@ -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());
}
}
@@ -1,4 +1,4 @@
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.
@@ -6,7 +6,7 @@ tests/cases/compiler/a.js(3,12): error TS8010: 'types' can only be used in a .ts
@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.
@@ -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.
@@ -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.
@@ -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) ====
@@ -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.
};
}
@@ -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) ====
@@ -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 },
}`,
},
});