From cdf750a8f45a5acab1e5cc9ef27602370b72327f Mon Sep 17 00:00:00 2001 From: Sathya Gunasekaran Date: Tue, 13 Nov 2018 15:53:13 +0000 Subject: [PATCH] [parser] Split out ParsePropertyKind::kShortHand With this we can just shortcircuit parsing if we see an incorrect Token::COMMA or Token::COLON when parsing class literals. Change-Id: Idd0c0c33b035b821ed23174f9cb1b12616a2a621 Reviewed-on: https://chromium-review.googlesource.com/c/1333678 Reviewed-by: Toon Verwaest Commit-Queue: Sathya Gunasekaran Cr-Commit-Position: refs/heads/master@{#57481} --- src/parsing/parser-base.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h index 7130a81a02..e9d9e331fe 100644 --- a/src/parsing/parser-base.h +++ b/src/parsing/parser-base.h @@ -180,8 +180,10 @@ enum class ParsePropertyKind : uint8_t { kAccessorSetter, kValue, kShorthand, + kAssign, kMethod, kClassField, + kShorthandOrClassField, kSpread, kNotSet }; @@ -1927,10 +1929,14 @@ inline bool ParsePropertyKindFromToken(Token::Value token, *kind = ParsePropertyKind::kValue; return true; case Token::COMMA: - case Token::RBRACE: - case Token::ASSIGN: *kind = ParsePropertyKind::kShorthand; return true; + case Token::RBRACE: + *kind = ParsePropertyKind::kShorthandOrClassField; + return true; + case Token::ASSIGN: + *kind = ParsePropertyKind::kAssign; + return true; case Token::LPAREN: *kind = ParsePropertyKind::kMethod; return true; @@ -2138,7 +2144,9 @@ ParserBase::ParseClassPropertyDefinition( } switch (kind) { + case ParsePropertyKind::kAssign: case ParsePropertyKind::kClassField: + case ParsePropertyKind::kShorthandOrClassField: case ParsePropertyKind::kNotSet: // This case is a name followed by a name // or other property. Here we have to // assume that's an uninitialized field @@ -2147,8 +2155,6 @@ ParserBase::ParseClassPropertyDefinition( // semicolon. If not, there will be a // syntax error after parsing the first // name as an uninitialized field. - case ParsePropertyKind::kShorthand: - case ParsePropertyKind::kValue: if (allow_harmony_public_fields() || allow_harmony_private_fields()) { *property_kind = ClassLiteralProperty::FIELD; *is_private = name_token == Token::PRIVATE_NAME; @@ -2242,6 +2248,8 @@ ParserBase::ParseClassPropertyDefinition( impl()->SetFunctionNameFromPropertyName(result, *name, prefix); return result; } + case ParsePropertyKind::kValue: + case ParsePropertyKind::kShorthand: case ParsePropertyKind::kSpread: ReportUnexpectedTokenAt( Scanner::Location(name_token_position, name_expression->position()), @@ -2354,6 +2362,8 @@ ParserBase::ParseObjectPropertyDefinition(bool* has_seen_proto, return result; } + case ParsePropertyKind::kAssign: + case ParsePropertyKind::kShorthandOrClassField: case ParsePropertyKind::kShorthand: { // PropertyDefinition // IdentifierReference