Commit 0b271def authored by adamk's avatar adamk Committed by Commit bot

Cleanup destructuring-related error reporting in ParserBase

Several minor cleanups to error handling in expression parsing:
  - Remove duplication of binding and assignment error reporting.
  - RecordBindingPatternError calls are changed to shorter BindingPatternUnexpectedToken
    calls where possible.
  - No-op error recording calls are removed.

Review URL: https://codereview.chromium.org/1688833004

Cr-Commit-Position: refs/heads/master@{#33915}
parent 58a9bc5b
...@@ -984,7 +984,6 @@ template <class Traits> ...@@ -984,7 +984,6 @@ template <class Traits>
void ParserBase<Traits>::GetUnexpectedTokenMessage( void ParserBase<Traits>::GetUnexpectedTokenMessage(
Token::Value token, MessageTemplate::Template* message, const char** arg, Token::Value token, MessageTemplate::Template* message, const char** arg,
MessageTemplate::Template default_) { MessageTemplate::Template default_) {
// Four of the tokens are treated specially
switch (token) { switch (token) {
case Token::EOS: case Token::EOS:
*message = MessageTemplate::kUnexpectedEOS; *message = MessageTemplate::kUnexpectedEOS;
...@@ -1108,10 +1107,8 @@ ParserBase<Traits>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier, ...@@ -1108,10 +1107,8 @@ ParserBase<Traits>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier,
scanner()->location(), MessageTemplate::kStrongUndefined); scanner()->location(), MessageTemplate::kStrongUndefined);
if (is_strong(language_mode())) { if (is_strong(language_mode())) {
// TODO(dslomov): allow 'undefined' in nested patterns. // TODO(dslomov): allow 'undefined' in nested patterns.
classifier->RecordBindingPatternError( classifier->RecordPatternError(scanner()->location(),
scanner()->location(), MessageTemplate::kStrongUndefined); MessageTemplate::kStrongUndefined);
classifier->RecordAssignmentPatternError(
scanner()->location(), MessageTemplate::kStrongUndefined);
} }
} }
...@@ -1276,8 +1273,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, ...@@ -1276,8 +1273,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
return this->ExpressionFromLiteral(Next(), beg_pos, scanner(), factory()); return this->ExpressionFromLiteral(Next(), beg_pos, scanner(), factory());
case Token::SMI: case Token::SMI:
case Token::NUMBER: case Token::NUMBER:
classifier->RecordBindingPatternError( BindingPatternUnexpectedToken(classifier);
scanner()->peek_location(), MessageTemplate::kUnexpectedTokenNumber);
return this->ExpressionFromLiteral(Next(), beg_pos, scanner(), factory()); return this->ExpressionFromLiteral(Next(), beg_pos, scanner(), factory());
case Token::IDENTIFIER: case Token::IDENTIFIER:
...@@ -1293,8 +1289,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, ...@@ -1293,8 +1289,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
} }
case Token::STRING: { case Token::STRING: {
classifier->RecordBindingPatternError( BindingPatternUnexpectedToken(classifier);
scanner()->peek_location(), MessageTemplate::kUnexpectedTokenString);
Consume(Token::STRING); Consume(Token::STRING);
return this->ExpressionFromString(beg_pos, scanner(), factory()); return this->ExpressionFromString(beg_pos, scanner(), factory());
} }
...@@ -1340,9 +1335,6 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, ...@@ -1340,9 +1335,6 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
classifier->RecordExpressionError(scanner()->location(), classifier->RecordExpressionError(scanner()->location(),
MessageTemplate::kUnexpectedToken, MessageTemplate::kUnexpectedToken,
Token::String(Token::RPAREN)); Token::String(Token::RPAREN));
classifier->RecordBindingPatternError(scanner()->location(),
MessageTemplate::kUnexpectedToken,
Token::String(Token::RPAREN));
return factory()->NewEmptyParentheses(beg_pos); return factory()->NewEmptyParentheses(beg_pos);
} else if (Check(Token::ELLIPSIS)) { } else if (Check(Token::ELLIPSIS)) {
// (...x)=>x. The continuation that looks for the => is in // (...x)=>x. The continuation that looks for the => is in
...@@ -1403,9 +1395,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier, ...@@ -1403,9 +1395,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
case Token::TEMPLATE_SPAN: case Token::TEMPLATE_SPAN:
case Token::TEMPLATE_TAIL: case Token::TEMPLATE_TAIL:
classifier->RecordBindingPatternError( BindingPatternUnexpectedToken(classifier);
scanner()->peek_location(),
MessageTemplate::kUnexpectedTemplateString);
return this->ParseTemplateLiteral(Traits::NoTemplateTag(), beg_pos, return this->ParseTemplateLiteral(Traits::NoTemplateTag(), beg_pos,
classifier, ok); classifier, ok);
...@@ -1990,7 +1980,9 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags, ...@@ -1990,7 +1980,9 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags,
ExpressionT expression = this->ParseConditionalExpression( ExpressionT expression = this->ParseConditionalExpression(
accept_IN, &arrow_formals_classifier, CHECK_OK); accept_IN, &arrow_formals_classifier, CHECK_OK);
if (peek() == Token::ARROW) { if (peek() == Token::ARROW) {
BindingPatternUnexpectedToken(classifier); classifier->RecordPatternError(scanner()->peek_location(),
MessageTemplate::kUnexpectedToken,
Token::String(Token::ARROW));
ValidateArrowFormalParameters(&arrow_formals_classifier, expression, ValidateArrowFormalParameters(&arrow_formals_classifier, expression,
parenthesized_formals, CHECK_OK); parenthesized_formals, CHECK_OK);
Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos); Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos);
...@@ -2018,11 +2010,6 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags, ...@@ -2018,11 +2010,6 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags,
} }
expression = this->ParseArrowFunctionLiteral( expression = this->ParseArrowFunctionLiteral(
accept_IN, parameters, arrow_formals_classifier, CHECK_OK); accept_IN, parameters, arrow_formals_classifier, CHECK_OK);
if (maybe_pattern_element) {
classifier->RecordPatternError(
Scanner::Location(lhs_beg_pos, scanner()->location().end_pos),
MessageTemplate::kInvalidDestructuringTarget);
}
if (fni_ != nullptr) fni_->Infer(); if (fni_ != nullptr) fni_->Infer();
...@@ -2081,9 +2068,9 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags, ...@@ -2081,9 +2068,9 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags,
Token::Value op = Next(); // Get assignment operator. Token::Value op = Next(); // Get assignment operator.
if (op != Token::ASSIGN) { if (op != Token::ASSIGN) {
classifier->RecordBindingPatternError(scanner()->location(), classifier->RecordPatternError(scanner()->location(),
MessageTemplate::kUnexpectedToken, MessageTemplate::kUnexpectedToken,
Token::String(op)); Token::String(op));
} }
int pos = position(); int pos = position();
...@@ -2105,12 +2092,6 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags, ...@@ -2105,12 +2092,6 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, int flags,
function_state_->AddProperty(); function_state_->AddProperty();
} }
if (op != Token::ASSIGN && maybe_pattern_element) {
classifier->RecordAssignmentPatternError(
Scanner::Location(lhs_beg_pos, scanner()->location().end_pos),
MessageTemplate::kInvalidDestructuringTarget);
}
this->CheckAssigningFunctionLiteralToProperty(expression, right); this->CheckAssigningFunctionLiteralToProperty(expression, right);
if (fni_ != NULL) { if (fni_ != NULL) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment