[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 <verwaest@chromium.org> Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org> Cr-Commit-Position: refs/heads/master@{#57481}
This commit is contained in:
parent
589af9f257
commit
cdf750a8f4
@ -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<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
|
||||
|
Loading…
Reference in New Issue
Block a user