Skip to content

Commit 9cc092a

Browse files
committed
Merge pull request microsoft#6881 from Microsoft/issue6872
Allow decorators in JavaScript files
2 parents 9e60af8 + fe60490 commit 9cc092a

11 files changed

Lines changed: 25 additions & 33 deletions

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12791,7 +12791,7 @@ namespace ts {
1279112791
}
1279212792

1279312793
if (!compilerOptions.experimentalDecorators) {
12794-
error(node, Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalDecorators_to_remove_this_warning);
12794+
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);
1279512795
}
1279612796

1279712797
if (compilerOptions.emitDecoratorMetadata) {

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@
687687
"category": "Error",
688688
"code": 1218
689689
},
690-
"Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning.": {
690+
"Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.": {
691691
"category": "Error",
692692
"code": 1219
693693
},
@@ -2729,11 +2729,6 @@
27292729
"category": "Error",
27302730
"code": 8016
27312731
},
2732-
"'decorators' can only be used in a .ts file.": {
2733-
"category": "Error",
2734-
"code": 8017
2735-
},
2736-
27372732
"Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses.": {
27382733
"category": "Error",
27392734
"code": 9002

src/compiler/program.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,9 @@ namespace ts {
11691169
diagnostics.push(createDiagnosticForNode(typeAssertionExpression.type, Diagnostics.type_assertion_expressions_can_only_be_used_in_a_ts_file));
11701170
return true;
11711171
case SyntaxKind.Decorator:
1172-
diagnostics.push(createDiagnosticForNode(node, Diagnostics.decorators_can_only_be_used_in_a_ts_file));
1172+
if (!options.experimentalDecorators) {
1173+
diagnostics.push(createDiagnosticForNode(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));
1174+
}
11731175
return true;
11741176
}
11751177

tests/baselines/reference/generatorTypeCheck39.errors.txt

Lines changed: 2 additions & 2 deletions
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. Specify '--experimentalDecorators' 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 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. Specify '--experimentalDecorators' 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 to remove this warning.
1717
x = yield 0;
1818
~~~~~
1919
!!! error TS1163: A 'yield' expression is only allowed in a generator body.

tests/baselines/reference/generatorTypeCheck59.errors.txt

Lines changed: 2 additions & 2 deletions
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. Specify '--experimentalDecorators' 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 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. Specify '--experimentalDecorators' 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 to remove this warning.
1414
};
1515
}
Lines changed: 2 additions & 2 deletions
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. Specify '--experimentalDecorators' 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 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. Specify '--experimentalDecorators' 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 to remove this warning.
1313
}

tests/baselines/reference/jsFileCompilationDecoratorSyntax.errors.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
=== tests/cases/compiler/a.js ===
2+
@internal class C { }
3+
>C : Symbol(C, Decl(a.js, 0, 0))
4+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== tests/cases/compiler/a.js ===
2+
@internal class C { }
3+
>internal : any
4+
>C : C
5+
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
// @allowJs: true
2+
// @noEmit: true
3+
// @experimentalDecorators: true
24
// @filename: a.js
3-
@internal class C { }
5+
@internal class C { }

0 commit comments

Comments
 (0)