Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Unified Diff: src/parsing/parser-base.h

Issue 2267223002: [cleanup] Eliminate Forgive* methods on ExpressionClassifier (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Move Pattern production logic around Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parsing/expression-classifier.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser-base.h
diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h
index de30e1bc5420eecdb42810f53c16976baa6b8235..03ef462bf71f6d1b1e7e257a240b035dc61d83d9 100644
--- a/src/parsing/parser-base.h
+++ b/src/parsing/parser-base.h
@@ -2281,7 +2281,6 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
// ArrowFunction
// YieldExpression
// LeftHandSideExpression AssignmentOperator AssignmentExpression
- bool is_destructuring_assignment = false;
int lhs_beg_pos = peek_position();
if (peek() == Token::YIELD && is_generator()) {
@@ -2376,21 +2375,38 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
return expression;
}
+ // "expression" was not itself an arrow function parameter list, but it might
+ // form part of one. Propagate speculative formal parameter error locations
+ // (including those for binding patterns, since formal parameters can
+ // themselves contain binding patterns).
+ // Do not merge pending non-pattern expressions yet!
+ unsigned productions =
+ ExpressionClassifier::FormalParametersProductions |
+ ExpressionClassifier::AsyncArrowFormalParametersProduction |
+ ExpressionClassifier::FormalParameterInitializerProduction;
+
+ // Parenthesized identifiers and property references are allowed as part
+ // of a larger binding pattern, even though parenthesized patterns
+ // themselves are not allowed, e.g., "[(x)] = []". Only accumulate
+ // assignment pattern errors if the parsed expression is more complex.
if (this->IsValidReferenceExpression(expression)) {
- arrow_formals_classifier.ForgiveAssignmentPatternError();
+ productions |= ExpressionClassifier::PatternProductions &
+ ~ExpressionClassifier::AssignmentPatternProduction;
+ } else {
+ productions |= ExpressionClassifier::PatternProductions;
}
- // "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,
- ExpressionClassifier::ExpressionProductions |
- ExpressionClassifier::PatternProductions |
- ExpressionClassifier::FormalParametersProductions |
- ExpressionClassifier::ObjectLiteralProduction |
- ExpressionClassifier::AsyncArrowFormalParametersProduction,
- false);
+ const bool is_destructuring_assignment =
+ IsValidPattern(expression) && peek() == Token::ASSIGN;
+ if (!is_destructuring_assignment) {
+ // This may be an expression or a pattern, so we must continue to
+ // accumulate expression-related errors.
+ productions |= ExpressionClassifier::ExpressionProduction |
+ ExpressionClassifier::TailCallExpressionProduction |
+ ExpressionClassifier::ObjectLiteralProduction;
+ }
+
+ classifier->Accumulate(&arrow_formals_classifier, productions, false);
if (!Token::IsAssignmentOp(peek())) {
// Parsed conditional expression only (no assignment).
@@ -2404,10 +2420,8 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
CheckNoTailCallExpressions(classifier, CHECK_OK);
- if (IsValidPattern(expression) && peek() == Token::ASSIGN) {
- classifier->ForgiveObjectLiteralError();
+ if (is_destructuring_assignment) {
ValidateAssignmentPattern(classifier, CHECK_OK);
- is_destructuring_assignment = true;
} else {
expression = this->CheckAndRewriteReferenceExpression(
expression, lhs_beg_pos, scanner()->location().end_pos,
« no previous file with comments | « src/parsing/expression-classifier.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698