From cbfbae94fd866ee1912d2af0ab36b92a0998b530 Mon Sep 17 00:00:00 2001 From: Chris Bubernak Date: Sun, 5 Oct 2014 22:21:43 -0700 Subject: [PATCH] Added a message & a check for numerics in the parser --- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 16 ++++++++++------ src/compiler/parser.ts | 5 +++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index dec1c00027b..927a85ff854 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -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." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 79208be1a0d..c41bb962971 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -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()' 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 }, diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 422d133d5d0..61afdb7e546 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3673,6 +3673,11 @@ module ts { var node = 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) {