diff --git a/src/services/resources/diagnosticCode.generated.ts b/src/services/resources/diagnosticCode.generated.ts index 445aa48d5ec..d8533c0a6ee 100644 --- a/src/services/resources/diagnosticCode.generated.ts +++ b/src/services/resources/diagnosticCode.generated.ts @@ -103,6 +103,7 @@ module TypeScript { async_arrow_function_parameters_must_be_parenthesized: "'async' arrow function parameters must be parenthesized.", A_generator_declaration_cannot_have_the_async_modifier: "A generator declaration cannot have the 'async' modifier.", async_modifier_cannot_appear_here: "'async' modifier cannot appear here.", + comma_expression_cannot_appear_in_a_computed_property_name: "'comma' expression cannot appear in a computed property name.", Duplicate_identifier_0: "Duplicate identifier '{0}'.", The_name_0_does_not_exist_in_the_current_scope: "The name '{0}' does not exist in the current scope.", The_name_0_does_not_refer_to_a_value: "The name '{0}' does not refer to a value.", diff --git a/src/services/resources/diagnosticInformationMap.generated.ts b/src/services/resources/diagnosticInformationMap.generated.ts index 3aea88053d3..5bbe9b43dbb 100644 --- a/src/services/resources/diagnosticInformationMap.generated.ts +++ b/src/services/resources/diagnosticInformationMap.generated.ts @@ -105,6 +105,7 @@ module TypeScript { "'async' arrow function parameters must be parenthesized.": { "code": 1117, "category": DiagnosticCategory.Error }, "A generator declaration cannot have the 'async' modifier.": { "code": 1118, "category": DiagnosticCategory.Error }, "'async' modifier cannot appear here.": { "code": 1119, "category": DiagnosticCategory.Error }, + "'comma' expression cannot appear in a computed property name.": { "code": 1120, "category": DiagnosticCategory.Error }, "Duplicate identifier '{0}'.": { "code": 2000, "category": DiagnosticCategory.Error }, "The name '{0}' does not exist in the current scope.": { "code": 2001, "category": DiagnosticCategory.Error }, "The name '{0}' does not refer to a value.": { "code": 2002, "category": DiagnosticCategory.Error }, diff --git a/src/services/resources/diagnosticMessages.json b/src/services/resources/diagnosticMessages.json index 4a8c1e23ec7..b8e3cb26a00 100644 --- a/src/services/resources/diagnosticMessages.json +++ b/src/services/resources/diagnosticMessages.json @@ -407,6 +407,10 @@ "category": "Error", "code": 1119 }, + "'comma' expression cannot appear in a computed property name.": { + "category": "Error", + "code": 1120 + }, "Duplicate identifier '{0}'.": { "category": "Error", "code": 2000 diff --git a/src/services/syntax/parser.ts b/src/services/syntax/parser.ts index 8098b5a4d8b..ab33c1f7ed2 100644 --- a/src/services/syntax/parser.ts +++ b/src/services/syntax/parser.ts @@ -3753,9 +3753,11 @@ module TypeScript.Parser { // ComputedPropertyName[Yield] : // [AssignmentExpression[In, ?Yield]] + // Note: we allow any expression inside the computed property name. We'll report any + // issues later in the grammar checker if an invalid expression is provided. return new ComputedPropertyNameSyntax(contextFlags, eatToken(SyntaxKind.OpenBracketToken), - allowInAnd(parseAssignmentExpressionOrHigher), + allowInAnd(parseExpression), eatToken(SyntaxKind.CloseBracketToken)); } diff --git a/src/services/syntax/syntaxTree.ts b/src/services/syntax/syntaxTree.ts index 3bb40d6f5f8..5f5694123e2 100644 --- a/src/services/syntax/syntaxTree.ts +++ b/src/services/syntax/syntaxTree.ts @@ -1040,6 +1040,15 @@ module TypeScript { super.visitBreakStatement(node); } + public visitComputedPropertyName(node: ComputedPropertyNameSyntax): void { + if (node.expression.kind === SyntaxKind.BinaryExpression && (node.expression).operatorToken.kind === SyntaxKind.CommaToken) { + this.pushDiagnostic((node.expression).operatorToken, DiagnosticCode.comma_expression_cannot_appear_in_a_computed_property_name); + return; + } + + super.visitComputedPropertyName(node); + } + public visitContinueStatement(node: ContinueStatementSyntax): void { if (this.checkForStatementInAmbientContxt(node) || this.checkContinueStatementTarget(node)) {