Skip to content

Commit 49b3f85

Browse files
committed
disallow ambient const enums in 'separate compilation' mode
1 parent c885f59 commit 49b3f85

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10159,6 +10159,11 @@ module ts {
1015910159

1016010160
computeEnumMemberValues(node);
1016110161

10162+
let enumIsConst = isConst(node);
10163+
if (compilerOptions.separateCompilation && enumIsConst && isInAmbientContext(node)) {
10164+
error(node.name, Diagnostics.Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided);
10165+
}
10166+
1016210167
// Spec 2014 - Section 9.3:
1016310168
// It isn't possible for one enum declaration to continue the automatic numbering sequence of another,
1016410169
// and when an enum type has multiple declarations, only one declaration is permitted to omit a value
@@ -10169,7 +10174,6 @@ module ts {
1016910174
let firstDeclaration = getDeclarationOfKind(enumSymbol, node.kind);
1017010175
if (node === firstDeclaration) {
1017110176
if (enumSymbol.declarations.length > 1) {
10172-
let enumIsConst = isConst(node);
1017310177
// check that const is placed\omitted on all enum declarations
1017410178
forEach(enumSymbol.declarations, decl => {
1017510179
if (isConstEnumDeclaration(decl) !== enumIsConst) {

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ module ts {
166166
Decorators_are_not_valid_here: { code: 1206, category: DiagnosticCategory.Error, key: "Decorators are not valid here." },
167167
Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." },
168168
Cannot_compile_non_external_modules_when_the_separateCompilation_flag_is_provided: { code: 1208, category: DiagnosticCategory.Error, key: "Cannot compile non-external modules when the '--separateCompilation' flag is provided." },
169+
Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided: { code: 1209, category: DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--separateCompilation' flag is provided." },
169170
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
170171
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." },
171172
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,10 @@
655655
"category": "Error",
656656
"code": 1208
657657
},
658+
"Ambient const enums are not allowed when the '--separateCompilation' flag is provided.": {
659+
"category": "Error",
660+
"code": 1209
661+
},
658662
"Duplicate identifier '{0}'.": {
659663
"category": "Error",
660664
"code": 2300

0 commit comments

Comments
 (0)