Skip to content

Commit 15547c0

Browse files
committed
Merge pull request #3330 from Microsoft/decoratorsExperiment
Added experimentalDecorators flag
2 parents 711886e + 62ba369 commit 15547c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+86
-6
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8942,6 +8942,10 @@ module ts {
89428942
if (!nodeCanBeDecorated(node)) {
89438943
return;
89448944
}
8945+
8946+
if (!compilerOptions.experimentalDecorators) {
8947+
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);
8948+
}
89458949

89468950
if (compilerOptions.emitDecoratorMetadata) {
89478951
// we only need to perform these checks if we are emitting serialized type metadata for the target of a decorator.

src/compiler/commandLineParser.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,16 @@ module ts {
188188
type: "boolean",
189189
description: Diagnostics.Watch_input_files,
190190
},
191+
{
192+
name: "experimentalDecorators",
193+
type: "boolean",
194+
description: Diagnostics.Enables_experimental_support_for_ES7_decorators
195+
},
191196
{
192197
name: "emitDecoratorMetadata",
193198
type: "boolean",
194-
experimental: true
199+
experimental: true,
200+
description: Diagnostics.Enables_experimental_support_for_emitting_type_metadata_for_decorators
195201
}
196202
];
197203

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ module ts {
174174
Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1215, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" },
175175
Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." },
176176
Export_assignment_is_not_supported_when_module_flag_is_system: { code: 1218, category: DiagnosticCategory.Error, key: "Export assignment is not supported when '--module' flag is 'system'." },
177+
Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalDecorators_to_remove_this_warning: { code: 1219, category: DiagnosticCategory.Error, key: "Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning." },
177178
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
178179
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
179180
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
@@ -507,6 +508,9 @@ module ts {
507508
Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix: { code: 6060, category: DiagnosticCategory.Message, key: "Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix)." },
508509
NEWLINE: { code: 6061, category: DiagnosticCategory.Message, key: "NEWLINE" },
509510
Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, category: DiagnosticCategory.Error, key: "Argument for '--newLine' option must be 'CRLF' or 'LF'." },
511+
Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified: { code: 6064, category: DiagnosticCategory.Error, key: "Option 'experimentalDecorators' must also be specified when option 'emitDecoratorMetadata' is specified." },
512+
Enables_experimental_support_for_ES7_decorators: { code: 6065, category: DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." },
513+
Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." },
510514
Variable_0_implicitly_has_an_1_type: { code: 7005, category: DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." },
511515
Parameter_0_implicitly_has_an_1_type: { code: 7006, category: DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." },
512516
Member_0_implicitly_has_an_1_type: { code: 7008, category: DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." },

src/compiler/diagnosticMessages.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,10 @@
683683
"category": "Error",
684684
"code": 1218
685685
},
686+
"Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning.": {
687+
"category": "Error",
688+
"code": 1219
689+
},
686690

687691
"Duplicate identifier '{0}'.": {
688692
"category": "Error",
@@ -2018,7 +2022,18 @@
20182022
"category": "Error",
20192023
"code": 6062
20202024
},
2021-
2025+
"Option 'experimentalDecorators' must also be specified when option 'emitDecoratorMetadata' is specified.": {
2026+
"category": "Error",
2027+
"code": 6064
2028+
},
2029+
"Enables experimental support for ES7 decorators.": {
2030+
"category": "Message",
2031+
"code": 6065
2032+
},
2033+
"Enables experimental support for emitting type metadata for decorators.": {
2034+
"category": "Message",
2035+
"code": 6066
2036+
},
20222037

20232038
"Variable '{0}' implicitly has an '{1}' type.": {
20242039
"category": "Error",

src/compiler/program.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,11 @@ module ts {
635635
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_noEmit_cannot_be_specified_with_option_declaration));
636636
}
637637
}
638+
639+
if (options.emitDecoratorMetadata &&
640+
!options.experimentalDecorators) {
641+
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified));
642+
}
638643
}
639644
}
640645
}

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,7 @@ module ts {
16771677
version?: boolean;
16781678
watch?: boolean;
16791679
isolatedModules?: boolean;
1680+
experimentalDecorators?: boolean;
16801681
emitDecoratorMetadata?: boolean;
16811682
/* @internal */ stripInternal?: boolean;
16821683
[option: string]: string | number | boolean;

src/harness/harness.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,10 @@ module Harness {
998998
options.target = <any>setting.value;
999999
}
10001000
break;
1001+
1002+
case 'experimentaldecorators':
1003+
options.experimentalDecorators = setting.value === 'true';
1004+
break;
10011005

10021006
case 'emitdecoratormetadata':
10031007
options.emitDecoratorMetadata = setting.value === 'true';
@@ -1510,7 +1514,7 @@ module Harness {
15101514
"errortruncation", "usecasesensitivefilenames", "preserveconstenums",
15111515
"includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal",
15121516
"isolatedmodules", "inlinesourcemap", "maproot", "sourceroot",
1513-
"inlinesources", "emitdecoratormetadata"];
1517+
"inlinesources", "emitdecoratormetadata", "experimentaldecorators"];
15141518

15151519
function extractCompilerSettings(content: string): CompilerSetting[] {
15161520

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// @experimentaldecorators: true
12
var v = @decorate class C { static p = 1 };

tests/cases/compiler/noEmitHelpers2.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @noemithelpers: true
2+
// @experimentaldecorators: true
23
// @emitdecoratormetadata: true
34
// @target: es5
45

tests/cases/compiler/sourceMapValidationDecorators.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @sourcemap: true
22
// @target: es5
3+
// @experimentaldecorators: true
34
declare function ClassDecorator1(target: Function): void;
45
declare function ClassDecorator2(x: number): (target: Function) => void;
56
declare function PropertyDecorator1(target: Object, key: string | symbol, descriptor?: PropertyDescriptor): void;

0 commit comments

Comments
 (0)