Skip to content

Commit a14254c

Browse files
committed
Added an error condition for duplicate AMD module name assignments.
1 parent 843d3ec commit a14254c

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ module ts {
270270
Type_argument_candidate_1_is_not_a_valid_type_argument_because_it_is_not_a_supertype_of_candidate_0: { code: 2455, category: DiagnosticCategory.Error, key: "Type argument candidate '{1}' is not a valid type argument because it is not a supertype of candidate '{0}'." },
271271
Type_alias_0_circularly_references_itself: { code: 2456, category: DiagnosticCategory.Error, key: "Type alias '{0}' circularly references itself." },
272272
Type_alias_name_cannot_be_0: { code: 2457, category: DiagnosticCategory.Error, key: "Type alias name cannot be '{0}'" },
273+
A_module_cannot_have_multiple_AMD_module_names: { code: 2458, category: DiagnosticCategory.Error, key: "A module cannot have multiple AMD module names." },
273274
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
274275
Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4001, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." },
275276
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,10 @@
10761076
"category": "Error",
10771077
"code": 2457
10781078
},
1079+
"A module cannot have multiple AMD module names.": {
1080+
"category": "Error",
1081+
"code": 2458
1082+
},
10791083

10801084
"Import declaration '{0}' is using private name '{1}'.": {
10811085
"category": "Error",

src/compiler/parser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4242,6 +4242,9 @@ module ts {
42424242
var amdModuleNameRegEx = /^\/\/\/\s*<amd-module\s+name\s*=\s*('|")(.+?)\1/gim;
42434243
var amdModuleNameMatchResult = amdModuleNameRegEx.exec(comment);
42444244
if(amdModuleNameMatchResult) {
4245+
if(amdModuleName) {
4246+
errorAtPos(range.pos, range.end - range.pos, Diagnostics.A_module_cannot_have_multiple_AMD_module_names);
4247+
}
42454248
amdModuleName = amdModuleNameMatchResult[2];
42464249
}
42474250

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
tests/cases/compiler/amdModuleName2.ts(2,1): error TS2458: A module cannot have multiple AMD module names.
2+
3+
4+
==== tests/cases/compiler/amdModuleName2.ts (1 errors) ====
5+
///<amd-module name='FirstModuleName'/>
6+
///<amd-module name='SecondModuleName'/>
7+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8+
!!! error TS2458: A module cannot have multiple AMD module names.
9+
class Foo {
10+
x: number;
11+
constructor() {
12+
this.x = 5;
13+
}
14+
}
15+
export = Foo;
16+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@module: amd
2+
///<amd-module name='FirstModuleName'/>
3+
///<amd-module name='SecondModuleName'/>
4+
class Foo {
5+
x: number;
6+
constructor() {
7+
this.x = 5;
8+
}
9+
}
10+
export = Foo;

0 commit comments

Comments
 (0)