Commit cdf750a8 authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

[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/1333678Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57481}
parent 589af9f2
...@@ -180,8 +180,10 @@ enum class ParsePropertyKind : uint8_t { ...@@ -180,8 +180,10 @@ enum class ParsePropertyKind : uint8_t {
kAccessorSetter, kAccessorSetter,
kValue, kValue,
kShorthand, kShorthand,
kAssign,
kMethod, kMethod,
kClassField, kClassField,
kShorthandOrClassField,
kSpread, kSpread,
kNotSet kNotSet
}; };
...@@ -1927,9 +1929,13 @@ inline bool ParsePropertyKindFromToken(Token::Value token, ...@@ -1927,9 +1929,13 @@ inline bool ParsePropertyKindFromToken(Token::Value token,
*kind = ParsePropertyKind::kValue; *kind = ParsePropertyKind::kValue;
return true; return true;
case Token::COMMA: case Token::COMMA:
*kind = ParsePropertyKind::kShorthand;
return true;
case Token::RBRACE: case Token::RBRACE:
*kind = ParsePropertyKind::kShorthandOrClassField;
return true;
case Token::ASSIGN: case Token::ASSIGN:
*kind = ParsePropertyKind::kShorthand; *kind = ParsePropertyKind::kAssign;
return true; return true;
case Token::LPAREN: case Token::LPAREN:
*kind = ParsePropertyKind::kMethod; *kind = ParsePropertyKind::kMethod;
...@@ -2138,7 +2144,9 @@ ParserBase<Impl>::ParseClassPropertyDefinition( ...@@ -2138,7 +2144,9 @@ ParserBase<Impl>::ParseClassPropertyDefinition(
} }
switch (kind) { switch (kind) {
case ParsePropertyKind::kAssign:
case ParsePropertyKind::kClassField: case ParsePropertyKind::kClassField:
case ParsePropertyKind::kShorthandOrClassField:
case ParsePropertyKind::kNotSet: // This case is a name followed by a name case ParsePropertyKind::kNotSet: // This case is a name followed by a name
// or other property. Here we have to // or other property. Here we have to
// assume that's an uninitialized field // assume that's an uninitialized field
...@@ -2147,8 +2155,6 @@ ParserBase<Impl>::ParseClassPropertyDefinition( ...@@ -2147,8 +2155,6 @@ ParserBase<Impl>::ParseClassPropertyDefinition(
// semicolon. If not, there will be a // semicolon. If not, there will be a
// syntax error after parsing the first // syntax error after parsing the first
// name as an uninitialized field. // name as an uninitialized field.
case ParsePropertyKind::kShorthand:
case ParsePropertyKind::kValue:
if (allow_harmony_public_fields() || allow_harmony_private_fields()) { if (allow_harmony_public_fields() || allow_harmony_private_fields()) {
*property_kind = ClassLiteralProperty::FIELD; *property_kind = ClassLiteralProperty::FIELD;
*is_private = name_token == Token::PRIVATE_NAME; *is_private = name_token == Token::PRIVATE_NAME;
...@@ -2242,6 +2248,8 @@ ParserBase<Impl>::ParseClassPropertyDefinition( ...@@ -2242,6 +2248,8 @@ ParserBase<Impl>::ParseClassPropertyDefinition(
impl()->SetFunctionNameFromPropertyName(result, *name, prefix); impl()->SetFunctionNameFromPropertyName(result, *name, prefix);
return result; return result;
} }
case ParsePropertyKind::kValue:
case ParsePropertyKind::kShorthand:
case ParsePropertyKind::kSpread: case ParsePropertyKind::kSpread:
ReportUnexpectedTokenAt( ReportUnexpectedTokenAt(
Scanner::Location(name_token_position, name_expression->position()), Scanner::Location(name_token_position, name_expression->position()),
...@@ -2354,6 +2362,8 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(bool* has_seen_proto, ...@@ -2354,6 +2362,8 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(bool* has_seen_proto,
return result; return result;
} }
case ParsePropertyKind::kAssign:
case ParsePropertyKind::kShorthandOrClassField:
case ParsePropertyKind::kShorthand: { case ParsePropertyKind::kShorthand: {
// PropertyDefinition // PropertyDefinition
// IdentifierReference // IdentifierReference
......
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