Chromium Code Reviews| Index: src/parsing/parser-base.h |
| diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h |
| index a946cfa6bc825bbca6162cdaf4d97105f6c9aa4c..f3e65cb8d6135d736d23b83777c8dd40bf798957 100644 |
| --- a/src/parsing/parser-base.h |
| +++ b/src/parsing/parser-base.h |
| @@ -897,15 +897,17 @@ class ParserBase : public Traits { |
| ExpressionT expr, |
| bool parenthesized_formals, bool is_async, |
| bool* ok) { |
| - if (classifier->is_valid_binding_pattern()) { |
| + if (!is_async && classifier->is_valid_binding_pattern() && |
| + !this->IsIdentifier(expr)) { |
|
nickie
2016/07/12 12:27:13
Merging the conditions and removing the "else" cha
|
| // A simple arrow formal parameter: IDENTIFIER => BODY. |
| - if (!this->IsIdentifier(expr)) { |
| - Traits::ReportMessageAt(scanner()->location(), |
| - MessageTemplate::kUnexpectedToken, |
| - Token::String(scanner()->current_token())); |
| - *ok = false; |
| - } |
| - } else if (!classifier->is_valid_arrow_formal_parameters()) { |
| + Traits::ReportMessageAt(scanner()->location(), |
| + MessageTemplate::kUnexpectedToken, |
| + Token::String(scanner()->current_token())); |
| + *ok = false; |
| + return; |
| + } |
| + |
| + if (!classifier->is_valid_arrow_formal_parameters()) { |
| // If after parsing the expr, we see an error but the expression is |
| // neither a valid binding pattern nor a valid parenthesized formal |
| // parameter list, show the "arrow formal parameters" error if the formals |
| @@ -915,12 +917,22 @@ class ParserBase : public Traits { |
| : classifier->binding_pattern_error(); |
| ReportClassifierError(error); |
| *ok = false; |
| + return; |
| } |
| - if (is_async && !classifier->is_valid_async_arrow_formal_parameters()) { |
| - const typename ExpressionClassifier::Error& error = |
| - classifier->async_arrow_formal_parameters_error(); |
| - ReportClassifierError(error); |
| - *ok = false; |
| + |
| + if (is_async) { |
| + if (!classifier->is_valid_async_arrow_formal_parameters()) { |
| + const typename ExpressionClassifier::Error& error = |
| + classifier->async_arrow_formal_parameters_error(); |
| + ReportClassifierError(error); |
| + *ok = false; |
| + return; |
| + } |
| + if (!classifier->is_valid_binding_pattern()) { |
| + ReportClassifierError(classifier->binding_pattern_error()); |
| + *ok = false; |
| + return; |
| + } |
| } |
| } |
| @@ -1024,7 +1036,12 @@ class ParserBase : public Traits { |
| ExpressionT ParseAssignmentExpression(bool accept_IN, |
| ExpressionClassifier* classifier, |
| - bool* ok); |
| + bool merge_patterns, bool* ok); |
| + ExpressionT ParseAssignmentExpression(bool accept_IN, |
| + ExpressionClassifier* classifier, |
| + bool* ok) { |
| + return ParseAssignmentExpression(accept_IN, classifier, false, ok); |
| + } |
| ExpressionT ParseYieldExpression(bool accept_IN, |
| ExpressionClassifier* classifier, bool* ok); |
| ExpressionT ParseTailCallExpression(ExpressionClassifier* classifier, |
| @@ -2172,7 +2189,7 @@ typename Traits::Type::ExpressionList ParserBase<Traits>::ParseArguments( |
| int expr_pos = peek_position(); |
| ExpressionT argument = this->ParseAssignmentExpression( |
| - true, classifier, CHECK_OK_CUSTOM(NullExpressionList)); |
| + true, classifier, maybe_arrow, CHECK_OK_CUSTOM(NullExpressionList)); |
| CheckNoTailCallExpressions(classifier, CHECK_OK_CUSTOM(NullExpressionList)); |
| if (!maybe_arrow) { |
| Traits::RewriteNonPattern(classifier, |
| @@ -2239,7 +2256,7 @@ template <class Traits> |
| typename ParserBase<Traits>::ExpressionT |
| ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, |
| ExpressionClassifier* classifier, |
| - bool* ok) { |
| + bool merge_patterns, bool* ok) { |
| // AssignmentExpression :: |
| // ConditionalExpression |
| // ArrowFunction |
| @@ -2331,14 +2348,18 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, |
| // "expression" was not itself an arrow function parameter list, but it might |
| // form part of one. Propagate speculative formal parameter error locations. |
| // Do not merge pending non-pattern expressions yet! |
| - classifier->Accumulate( |
| - &arrow_formals_classifier, |
| + int productions_to_propagate = |
| ExpressionClassifier::StandardProductions | |
| - ExpressionClassifier::FormalParametersProductions | |
| - ExpressionClassifier::CoverInitializedNameProduction | |
| - ExpressionClassifier::AsyncArrowFormalParametersProduction | |
| - ExpressionClassifier::AsyncBindingPatternProduction, |
| - false); |
| + ExpressionClassifier::FormalParametersProductions | |
| + ExpressionClassifier::CoverInitializedNameProduction | |
| + ExpressionClassifier::AsyncArrowFormalParametersProduction | |
| + ExpressionClassifier::AsyncBindingPatternProduction; |
| + if (merge_patterns) { |
| + productions_to_propagate |= ExpressionClassifier::BindingPatternProduction; |
| + } |
| + |
| + classifier->Accumulate(&arrow_formals_classifier, productions_to_propagate, |
| + false); |
| if (!Token::IsAssignmentOp(peek())) { |
| // Parsed conditional expression only (no assignment). |
| @@ -2805,7 +2826,16 @@ ParserBase<Traits>::ParseLeftHandSideExpression( |
| CheckNoTailCallExpressions(classifier, CHECK_OK); |
| int pos; |
| Traits::RewriteNonPattern(classifier, CHECK_OK); |
| - BindingPatternUnexpectedToken(classifier); |
| + |
| + const char* arg; |
| + MessageTemplate::Template message = MessageTemplate::kUnexpectedToken; |
| + Scanner::Location location = scanner()->peek_location(); |
| + GetUnexpectedTokenMessage(peek(), &message, &location, &arg); |
| + |
| + if (!is_async) { |
| + classifier->RecordBindingPatternError(location, message, arg); |
| + } |
| + |
| if (scanner()->current_token() == Token::IDENTIFIER || |
| scanner()->current_token() == Token::SUPER || |
| scanner()->current_token() == Token::ASYNC) { |
| @@ -2837,6 +2867,8 @@ ParserBase<Traits>::ParseLeftHandSideExpression( |
| } |
| // async () => ... |
| return factory()->NewEmptyParentheses(pos); |
| + } else { |
| + classifier->ReplaceBindingPatternError(location, message, arg); |
| } |
| ArrowFormalParametersUnexpectedToken(classifier); |