Commit 8860eb44 authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Cleanup pattern error related code

- Reuse CheckDestructuringElement for object rest destructuring,
- don't duplicate eval/arguments detection in object patterns,
- don't unnecessarily locally validate expression when async(...) is a call,
- don't classify pattern error for Property since it's only invalid as a binding pattern.

Change-Id: I0eaf6abff39a563c2d6dc07dfbb17071c0f76caf
Reviewed-on: https://chromium-review.googlesource.com/c/1349282Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57782}
parent 49a79c90
...@@ -2049,23 +2049,15 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePropertyName( ...@@ -2049,23 +2049,15 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePropertyName(
ExpressionT expression = ParseAssignmentExpression(); ExpressionT expression = ParseAssignmentExpression();
*kind = ParsePropertyKind::kSpread; *kind = ParsePropertyKind::kSpread;
if (IsValidReferenceExpression(expression)) { CheckDestructuringElement(expression, expression->position(),
Accumulate(~ExpressionClassifier::PatternProduction); end_position());
if (expression->IsProperty()) { if (!IsValidReferenceExpression(expression)) {
classifier()->RecordBindingPatternError( classifier()->RecordBindingPatternError(
Scanner::Location(expression->position(), end_position()), Scanner::Location(expression->position(), end_position()),
MessageTemplate::kInvalidPropertyBindingPattern); MessageTemplate::kInvalidRestBindingPattern);
} classifier()->RecordPatternError(
} else { Scanner::Location(expression->position(), end_position()),
Accumulate(ExpressionClassifier::AllProductions); MessageTemplate::kInvalidRestAssignmentPattern);
if (expression->IsValidPattern()) {
classifier()->RecordBindingPatternError(
Scanner::Location(expression->position(), end_position()),
MessageTemplate::kInvalidRestBindingPattern);
classifier()->RecordPatternError(
Scanner::Location(expression->position(), end_position()),
MessageTemplate::kInvalidRestAssignmentPattern);
}
} }
if (peek() != Token::RBRACE) { if (peek() != Token::RBRACE) {
...@@ -2378,11 +2370,6 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(bool* has_seen_proto, ...@@ -2378,11 +2370,6 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(bool* has_seen_proto,
DCHECK(!*is_computed_name); DCHECK(!*is_computed_name);
if (impl()->IsEvalOrArguments(name) && is_strict(language_mode())) {
classifier()->RecordPatternError(scanner()->location(),
MessageTemplate::kStrictEvalArguments);
}
if (name_token == Token::LET) { if (name_token == Token::LET) {
classifier()->RecordLetPatternError( classifier()->RecordLetPatternError(
scanner()->location(), MessageTemplate::kLetInLexicalBinding); scanner()->location(), MessageTemplate::kLetInLexicalBinding);
...@@ -2395,8 +2382,8 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(bool* has_seen_proto, ...@@ -2395,8 +2382,8 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(bool* has_seen_proto,
ExpressionT lhs = ExpressionT lhs =
impl()->ExpressionFromIdentifier(name, next_loc.beg_pos); impl()->ExpressionFromIdentifier(name, next_loc.beg_pos);
if (!IsAssignableIdentifier(lhs)) { if (!IsAssignableIdentifier(lhs)) {
classifier()->RecordPatternError( classifier()->RecordPatternError(next_loc,
next_loc, MessageTemplate::kInvalidDestructuringTarget); MessageTemplate::kStrictEvalArguments);
} }
ExpressionT value; ExpressionT value;
...@@ -3105,8 +3092,6 @@ ParserBase<Impl>::ParseLeftHandSideContinuation(ExpressionT result) { ...@@ -3105,8 +3092,6 @@ ParserBase<Impl>::ParseLeftHandSideContinuation(ExpressionT result) {
return factory()->NewEmptyParentheses(pos); return factory()->NewEmptyParentheses(pos);
} }
} }
ValidateExpression();
classifier()->RecordPatternError(lparen_loc, classifier()->RecordPatternError(lparen_loc,
MessageTemplate::kUnexpectedToken, MessageTemplate::kUnexpectedToken,
Token::String(Token::LPAREN)); Token::String(Token::LPAREN));
...@@ -3119,8 +3104,6 @@ ParserBase<Impl>::ParseLeftHandSideContinuation(ExpressionT result) { ...@@ -3119,8 +3104,6 @@ ParserBase<Impl>::ParseLeftHandSideContinuation(ExpressionT result) {
fni_.RemoveLastFunction(); fni_.RemoveLastFunction();
if (!Token::IsPropertyOrCall(peek())) return result; if (!Token::IsPropertyOrCall(peek())) return result;
} else {
PatternUnexpectedToken();
} }
do { do {
...@@ -3147,6 +3130,7 @@ ParserBase<Impl>::ParseLeftHandSideContinuation(ExpressionT result) { ...@@ -3147,6 +3130,7 @@ ParserBase<Impl>::ParseLeftHandSideContinuation(ExpressionT result) {
/* Call */ /* Call */
case Token::LPAREN: { case Token::LPAREN: {
PatternUnexpectedToken();
int pos; int pos;
if (Token::IsCallable(scanner()->current_token())) { if (Token::IsCallable(scanner()->current_token())) {
// For call of an identifier we want to report position of // For call of an identifier we want to report position of
...@@ -3193,6 +3177,7 @@ ParserBase<Impl>::ParseLeftHandSideContinuation(ExpressionT result) { ...@@ -3193,6 +3177,7 @@ ParserBase<Impl>::ParseLeftHandSideContinuation(ExpressionT result) {
/* Call */ /* Call */
default: default:
PatternUnexpectedToken();
DCHECK(peek() == Token::TEMPLATE_SPAN || DCHECK(peek() == Token::TEMPLATE_SPAN ||
peek() == Token::TEMPLATE_TAIL); peek() == Token::TEMPLATE_TAIL);
result = ParseTemplateLiteral(result, position(), true); result = ParseTemplateLiteral(result, position(), true);
...@@ -4463,7 +4448,7 @@ bool ParserBase<Impl>::IsValidReferenceExpression(ExpressionT expression) { ...@@ -4463,7 +4448,7 @@ bool ParserBase<Impl>::IsValidReferenceExpression(ExpressionT expression) {
template <typename Impl> template <typename Impl>
void ParserBase<Impl>::CheckDestructuringElement(ExpressionT expression, void ParserBase<Impl>::CheckDestructuringElement(ExpressionT expression,
int begin, int end) { int begin, int end) {
if (expression->IsProperty() || IsAssignableIdentifier(expression)) { if (IsValidReferenceExpression(expression)) {
// Parenthesized identifiers and property references are allowed as part of // Parenthesized identifiers and property references are allowed as part of
// a larger assignment pattern, even though parenthesized patterns // a larger assignment pattern, even though parenthesized patterns
// themselves are not allowed, e.g., "[(x)] = []". Only accumulate // themselves are not allowed, e.g., "[(x)] = []". Only accumulate
......
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