Added a message & a check for numerics in the parser

This commit is contained in:
Chris Bubernak 2014-10-05 22:21:43 -07:00
parent 432fff1362
commit cbfbae94fd
3 changed files with 16 additions and 6 deletions

View File

@ -48,6 +48,7 @@ module ts {
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." },
Enum_member_must_have_initializer: { code: 1061, category: DiagnosticCategory.Error, key: "Enum member must have initializer." },
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." },
An_enum_member_cannot_have_a_numeric_name: { code: 1065, category: DiagnosticCategory.Error, key: "An enum member cannot have a numeric name." },
Ambient_enum_elements_can_only_have_integer_literal_initializers: { code: 1066, category: DiagnosticCategory.Error, key: "Ambient enum elements can only have integer literal initializers." },
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." },
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." },

View File

@ -11,7 +11,7 @@
"category": "Error",
"code": 1005
},
"A file cannot have a reference to itself.": {
"A file cannot have a reference to itself.": {
"category": "Error",
"code": 1006
},
@ -183,11 +183,15 @@
"category": "Error",
"code": 1063
},
"An enum member cannot have a numeric name.": {
"category": "Error",
"code": 1065
},
"Ambient enum elements can only have integer literal initializers.": {
"category": "Error",
"code": 1066
},
"Unexpected token. A constructor, method, accessor, or property was expected." : {
"Unexpected token. A constructor, method, accessor, or property was expected.": {
"category": "Error",
"code": 1068
},
@ -444,9 +448,9 @@
"code": 1149
},
"'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.": {
"category": "Error",
"code": 1150
},
"category": "Error",
"code": 1150
},
"Duplicate identifier '{0}'.": {
"category": "Error",
@ -556,7 +560,7 @@
"category": "Error",
"code": 2326
},
"Property '{0}' is optional in type '{1}' but required in type '{2}'.": {
"Property '{0}' is optional in type '{1}' but required in type '{2}'.": {
"category": "Error",
"code": 2327
},

View File

@ -3673,6 +3673,11 @@ module ts {
var node = <EnumMember>createNode(SyntaxKind.EnumMember);
var errorCountBeforeEnumMember = file.syntacticErrors.length;
node.name = parsePropertyName();
if(isIntegerLiteral(node.name)) {
grammarErrorOnNode(node.name, Diagnostics.An_enum_member_cannot_have_a_numeric_name);
}
node.initializer = parseInitializer(/*inParameter*/ false);
if (inAmbientContext) {