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 {
kAccessorSetter,
kValue,
kShorthand,
kAssign,
kMethod,
kClassField,
kShorthandOrClassField,
kSpread,
kNotSet
};
......@@ -1927,9 +1929,13 @@ inline bool ParsePropertyKindFromToken(Token::Value token,
*kind = ParsePropertyKind::kValue;
return true;
case Token::COMMA:
*kind = ParsePropertyKind::kShorthand;
return true;
case Token::RBRACE:
*kind = ParsePropertyKind::kShorthandOrClassField;
return true;
case Token::ASSIGN:
*kind = ParsePropertyKind::kShorthand;
*kind = ParsePropertyKind::kAssign;
return true;
case Token::LPAREN:
*kind = ParsePropertyKind::kMethod;
......@@ -2138,7 +2144,9 @@ ParserBase<Impl>::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<Impl>::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<Impl>::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<Impl>::ParseObjectPropertyDefinition(bool* has_seen_proto,
return result;
}
case ParsePropertyKind::kAssign:
case ParsePropertyKind::kShorthandOrClassField:
case ParsePropertyKind::kShorthand: {
// PropertyDefinition
// 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