Skip to content

Commit cbfbae9

Browse files
committed
Added a message & a check for numerics in the parser
1 parent 432fff1 commit cbfbae9

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module ts {
4848
Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1056, category: DiagnosticCategory.Error, key: "Accessors are only available when targeting ECMAScript 5 and higher." },
4949
Enum_member_must_have_initializer: { code: 1061, category: DiagnosticCategory.Error, key: "Enum member must have initializer." },
5050
An_export_assignment_cannot_be_used_in_an_internal_module: { code: 1063, category: DiagnosticCategory.Error, key: "An export assignment cannot be used in an internal module." },
51+
An_enum_member_cannot_have_a_numeric_name: { code: 1065, category: DiagnosticCategory.Error, key: "An enum member cannot have a numeric name." },
5152
Ambient_enum_elements_can_only_have_integer_literal_initializers: { code: 1066, category: DiagnosticCategory.Error, key: "Ambient enum elements can only have integer literal initializers." },
5253
Unexpected_token_A_constructor_method_accessor_or_property_was_expected: { code: 1068, category: DiagnosticCategory.Error, key: "Unexpected token. A constructor, method, accessor, or property was expected." },
5354
A_declare_modifier_cannot_be_used_with_an_import_declaration: { code: 1079, category: DiagnosticCategory.Error, key: "A 'declare' modifier cannot be used with an import declaration." },

src/compiler/diagnosticMessages.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"category": "Error",
1212
"code": 1005
1313
},
14-
"A file cannot have a reference to itself.": {
14+
"A file cannot have a reference to itself.": {
1515
"category": "Error",
1616
"code": 1006
1717
},
@@ -183,11 +183,15 @@
183183
"category": "Error",
184184
"code": 1063
185185
},
186+
"An enum member cannot have a numeric name.": {
187+
"category": "Error",
188+
"code": 1065
189+
},
186190
"Ambient enum elements can only have integer literal initializers.": {
187191
"category": "Error",
188192
"code": 1066
189193
},
190-
"Unexpected token. A constructor, method, accessor, or property was expected." : {
194+
"Unexpected token. A constructor, method, accessor, or property was expected.": {
191195
"category": "Error",
192196
"code": 1068
193197
},
@@ -444,9 +448,9 @@
444448
"code": 1149
445449
},
446450
"'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.": {
447-
"category": "Error",
448-
"code": 1150
449-
},
451+
"category": "Error",
452+
"code": 1150
453+
},
450454

451455
"Duplicate identifier '{0}'.": {
452456
"category": "Error",
@@ -556,7 +560,7 @@
556560
"category": "Error",
557561
"code": 2326
558562
},
559-
"Property '{0}' is optional in type '{1}' but required in type '{2}'.": {
563+
"Property '{0}' is optional in type '{1}' but required in type '{2}'.": {
560564
"category": "Error",
561565
"code": 2327
562566
},

src/compiler/parser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3673,6 +3673,11 @@ module ts {
36733673
var node = <EnumMember>createNode(SyntaxKind.EnumMember);
36743674
var errorCountBeforeEnumMember = file.syntacticErrors.length;
36753675
node.name = parsePropertyName();
3676+
3677+
if(isIntegerLiteral(node.name)) {
3678+
grammarErrorOnNode(node.name, Diagnostics.An_enum_member_cannot_have_a_numeric_name);
3679+
}
3680+
36763681
node.initializer = parseInitializer(/*inParameter*/ false);
36773682

36783683
if (inAmbientContext) {

0 commit comments

Comments
 (0)