Be more lenient with computed property names.

This commit is contained in:
Cyrus Najmabadi
2014-11-25 18:41:45 -08:00
parent 3d2979a50c
commit e6ada5fb81
5 changed files with 18 additions and 1 deletions
+3 -1
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));
}
+9
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)) {