Chromium Code Reviews| Index: src/preparser.h |
| diff --git a/src/preparser.h b/src/preparser.h |
| index 18fc2330eedd7f646683035bba73e311d6f8d12a..d0229ec2b7119f2a2a44f9b07f92971d2e671351 100644 |
| --- a/src/preparser.h |
| +++ b/src/preparser.h |
| @@ -1308,6 +1308,10 @@ class PreParserFactory { |
| return PreParserExpression::Spread(expression); |
| } |
| + PreParserExpression NewEmptyParentheses(int pos) { |
| + return PreParserExpression::Default(); |
| + } |
| + |
| // Return the object itself as AstVisitor and implement the needed |
| // dummy method right in this class. |
| PreParserFactory* visitor() { return this; } |
| @@ -2262,38 +2266,36 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, |
| } |
| BindingPatternUnexpectedToken(classifier); |
| Consume(Token::LPAREN); |
| - if (allow_harmony_arrow_functions() && Check(Token::RPAREN)) { |
| - // As a primary expression, the only thing that can follow "()" is "=>". |
| + if (Check(Token::RPAREN)) { |
| + // ()=>x. The continuation that looks for the => is in |
| + // ParseAssignmentExpression. |
| + classifier->RecordExpressionError(scanner()->location(), |
| + MessageTemplate::kUnexpectedToken, |
| + Token::String(Token::RPAREN)); |
| classifier->RecordBindingPatternError(scanner()->location(), |
| MessageTemplate::kUnexpectedToken, |
| Token::String(Token::RPAREN)); |
| - // Give a good error to the user who might have typed e.g. "return();". |
| - if (peek() != Token::ARROW) { |
| - ReportUnexpectedTokenAt(scanner_->peek_location(), peek(), |
| - MessageTemplate::kMissingArrow); |
| + result = factory()->NewEmptyParentheses(beg_pos); |
| + } else if (allow_harmony_rest_parameters() && Check(Token::ELLIPSIS)) { |
| + // (...x)=>x. The continuation that looks for the => is in |
| + // ParseAssignmentExpression. |
| + int ellipsis_pos = scanner()->location().beg_pos; |
| + classifier->RecordExpressionError(scanner()->location(), |
| + MessageTemplate::kUnexpectedToken, |
| + Token::String(Token::ELLIPSIS)); |
| + Scanner::Location expr_loc = scanner()->peek_location(); |
| + Token::Value tok = peek(); |
| + result = |
|
rossberg
2015/08/20 16:50:00
Nit: unnecessary line break?
wingo
2015/08/21 09:50:48
Done.
|
| + this->ParseAssignmentExpression(true, classifier, CHECK_OK); |
| + // Patterns not allowed as rest parameters. There is no way we can |
|
rossberg
2015/08/20 16:50:00
Nit: insert "are".
FWIW, Microsoft just proposed
wingo
2015/08/21 09:50:49
Done.
|
| + // succeed so go ahead and use the convenient ReportUnexpectedToken |
| + // interface. |
| + if (!Traits::IsIdentifier(result)) { |
| + ReportUnexpectedTokenAt(expr_loc, tok); |
| *ok = false; |
| return this->EmptyExpression(); |
| } |
| - Scope* scope = |
| - this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); |
| - FormalParametersT parameters(scope); |
| - scope->set_start_position(beg_pos); |
| - ExpressionClassifier args_classifier; |
| - result = this->ParseArrowFunctionLiteral(parameters, args_classifier, |
| - CHECK_OK); |
| - } else if (allow_harmony_arrow_functions() && |
| - allow_harmony_rest_parameters() && Check(Token::ELLIPSIS)) { |
| - // (...x) => y |
| - Scope* scope = |
| - this->NewScope(scope_, ARROW_SCOPE, FunctionKind::kArrowFunction); |
| - FormalParametersT formals(scope); |
| - scope->set_start_position(beg_pos); |
| - ExpressionClassifier formals_classifier; |
| - formals.has_rest = true; |
| - this->ParseFormalParameter(&formals, &formals_classifier, CHECK_OK); |
| - Traits::DeclareFormalParameter( |
| - formals.scope, formals.at(0), formals.is_simple, |
| - &formals_classifier); |
| + result = factory()->NewSpread(result, ellipsis_pos); |
| if (peek() == Token::COMMA) { |
| ReportMessageAt(scanner()->peek_location(), |
| MessageTemplate::kParamAfterRest); |
| @@ -2301,8 +2303,6 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, |
| return this->EmptyExpression(); |
| } |
| Expect(Token::RPAREN, CHECK_OK); |
| - result = this->ParseArrowFunctionLiteral(formals, formals_classifier, |
| - CHECK_OK); |
| } else { |
| // Heuristically try to detect immediately called functions before |
| // seeing the call parentheses. |
| @@ -2864,6 +2864,12 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, |
| return expression; |
| } |
| + // It could be that ParseConditionalExpression returned EmptyParentheses if it |
| + // saw () but we didn't see a => afterward. This is a sufficiently rare case |
| + // that we should probably make sure it results in an exception and sets OK to |
| + // false. |
| + // ValidateExpression(&arrow_formals_classifier, CHECK_OK); |
|
rossberg
2015/08/20 16:50:00
Hm?
wingo
2015/08/21 09:50:48
A vestige of a previous patch, oops! Removed.
|
| + |
| // "expression" was not itself an arrow function parameter list, but it might |
| // form part of one. Propagate speculative formal parameter error locations. |
| classifier->Accumulate(arrow_formals_classifier, |