Skip to content

Commit 5b79b94

Browse files
amaksimovich2RyanCavanaugh
authored andcommitted
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
1 parent b8e3c41 commit 5b79b94

14 files changed

+96
-14
lines changed

Diff for: src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25636,7 +25636,7 @@ namespace ts {
2563625636
}
2563725637

2563825638
if (!compilerOptions.experimentalDecorators) {
25639-
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);
25639+
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);
2564025640
}
2564125641

2564225642
const firstDecorator = node.decorators[0];

Diff for: src/compiler/diagnosticMessages.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@
691691
"category": "Error",
692692
"code": 1218
693693
},
694-
"Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.": {
694+
"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.": {
695695
"category": "Error",
696696
"code": 1219
697697
},

Diff for: src/compiler/program.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ namespace ts {
18161816

18171817
function walkArray(nodes: NodeArray<Node>) {
18181818
if (parent.decorators === nodes && !options.experimentalDecorators) {
1819-
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));
1819+
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));
18201820
}
18211821

18221822
switch (parent.kind) {

Diff for: src/services/codefixes/fixEnableExperimentalDecorators.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
namespace ts.codefix {
33
const fixId = "enableExperimentalDecorators";
44
const errorCodes = [
5-
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
5+
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
66
];
77
registerCodeFix({
88
errorCodes,
@@ -12,13 +12,20 @@ namespace ts.codefix {
1212
return undefined;
1313
}
1414

15-
const changes = textChanges.ChangeTracker.with(context, changeTracker => makeChange(changeTracker, configFile));
15+
const changes = textChanges.ChangeTracker.with(context, changeTracker => doChange(changeTracker, configFile));
1616
return [createCodeFixActionNoFixId(fixId, changes, Diagnostics.Enable_the_experimentalDecorators_option_in_your_configuration_file)];
1717
},
1818
fixIds: [fixId],
19+
getAllCodeActions: context => codeFixAll(context, errorCodes, (changes) => {
20+
const { configFile } = context.program.getCompilerOptions();
21+
if (configFile === undefined) {
22+
return undefined;
23+
}
24+
doChange(changes, configFile);
25+
}),
1926
});
2027

21-
function makeChange(changeTracker: textChanges.ChangeTracker, configFile: TsConfigSourceFile) {
28+
function doChange(changeTracker: textChanges.ChangeTracker, configFile: TsConfigSourceFile) {
2229
setJsonCompilerOptionValue(changeTracker, configFile, "experimentalDecorators", createTrue());
2330
}
2431
}

Diff for: tests/baselines/reference/decoratorInJsFile1.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
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.
1+
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.
22
tests/cases/compiler/a.js(3,12): error TS8010: 'types' can only be used in a .ts file.
33

44

55
==== tests/cases/compiler/a.js (2 errors) ====
66
@SomeDecorator
77
class SomeClass {
88
~~~~~~~~~
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.
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.
1010
foo(x: number) {
1111
~~~~~~
1212
!!! error TS8010: 'types' can only be used in a .ts file.

Diff for: tests/baselines/reference/generatorTypeCheck39.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(5,16): error TS1163: A 'yield' expression is only allowed in a generator body.
2-
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.
2+
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.
33
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(7,13): error TS1163: A 'yield' expression is only allowed in a generator body.
44

55

@@ -13,7 +13,7 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(7,13): erro
1313
!!! error TS1163: A 'yield' expression is only allowed in a generator body.
1414
class C {
1515
~
16-
!!! 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.
16+
!!! 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.
1717
x = yield 0;
1818
~~~~~
1919
!!! error TS1163: A 'yield' expression is only allowed in a generator body.

Diff for: tests/baselines/reference/generatorTypeCheck59.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts(3,11): error TS1163: A 'yield' expression is only allowed in a generator body.
2-
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.
2+
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.
33

44

55
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts (2 errors) ====
@@ -10,6 +10,6 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts(4,9): error
1010
!!! error TS1163: A 'yield' expression is only allowed in a generator body.
1111
m() { }
1212
~
13-
!!! 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.
13+
!!! 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.
1414
};
1515
}
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts(2,7): error TS1163: A 'yield' expression is only allowed in a generator body.
2-
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.
2+
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.
33

44

55
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts (2 errors) ====
@@ -9,5 +9,5 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts(3,11): erro
99
!!! error TS1163: A 'yield' expression is only allowed in a generator body.
1010
class C {};
1111
~
12-
!!! 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.
12+
!!! 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.
1313
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: /dir/a.ts
4+
////declare const decorator: any;
5+
////class A {
6+
//// @decorator method() {};
7+
////};
8+
9+
// @Filename: /dir/jsconfig.json
10+
////{
11+
//// "compilerOptions": {
12+
//// }
13+
////}
14+
15+
goTo.file("/dir/a.ts");
16+
verify.codeFix({
17+
description: "Enable the 'experimentalDecorators' option in your configuration file",
18+
newFileContent: {
19+
"/dir/jsconfig.json":
20+
`{
21+
"compilerOptions": {
22+
"experimentalDecorators": true,
23+
}
24+
}`,
25+
},
26+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: /dir/a.ts
4+
////declare const decorator: any;
5+
////class A {
6+
//// @decorator method() {};
7+
////};
8+
9+
// @Filename: /dir/jsconfig.json
10+
////{
11+
//// "compilerOptions": {
12+
//// "experimentalDecorators": false,
13+
//// }
14+
////}
15+
16+
goTo.file("/dir/a.ts");
17+
verify.codeFix({
18+
description: "Enable the 'experimentalDecorators' option in your configuration file",
19+
newFileContent: {
20+
"/dir/jsconfig.json":
21+
`{
22+
"compilerOptions": {
23+
"experimentalDecorators": true,
24+
}
25+
}`,
26+
},
27+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @Filename: /dir/a.ts
4+
////declare const decorator: any;
5+
////class A {
6+
//// @decorator method() {};
7+
////};
8+
9+
// @Filename: /dir/jsconfig.json
10+
////{
11+
////}
12+
13+
goTo.file("/dir/a.ts");
14+
verify.codeFix({
15+
description: "Enable the 'experimentalDecorators' option in your configuration file",
16+
newFileContent: {
17+
"/dir/jsconfig.json":
18+
`{
19+
"compilerOptions": { "experimentalDecorators": true },
20+
}`,
21+
},
22+
});

0 commit comments

Comments
 (0)