Be more lenient with computed property names.

This commit is contained in:
Cyrus Najmabadi 2014-11-25 18:39:59 -08:00
parent 3d2979a50c
commit e6ada5fb81
5 changed files with 18 additions and 1 deletions

View File

@ -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.",

View File

@ -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 },

View File

@ -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

View File

@ -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));
}

View File

@ -1040,6 +1040,15 @@ module TypeScript {
super.visitBreakStatement(node);
}
public visitComputedPropertyName(node: ComputedPropertyNameSyntax): void {
if (node.expression.kind === SyntaxKind.BinaryExpression && (<BinaryExpressionSyntax>node.expression).operatorToken.kind === SyntaxKind.CommaToken) {
this.pushDiagnostic((<BinaryExpressionSyntax>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)) {