Issue #2142 - Implement ASI for fields

Based-on: m-c 1529772/{3,4}
This commit is contained in:
Martok 2023-04-09 04:03:27 +02:00 committed by roytam1
commit 447261cf87
2 changed files with 16 additions and 21 deletions

View file

@ -7485,13 +7485,7 @@ Parser<ParseHandler>::classMember(YieldHandling yieldHandling, DefaultHandling d
if (!initializer)
return false;
if (!tokenStream.getToken(&tt)) {
return false;
}
// TODO(khyperia): Implement ASI
if (tt != TOK_SEMI) {
error(JSMSG_MISSING_SEMI_FIELD);
if (!matchOrInsertSemicolonAfterExpression()) {
return false;
}
@ -10639,10 +10633,11 @@ Parser<ParseHandler>::propertyOrMethodName(YieldHandling yieldHandling,
// In the last case, where there's not a `:` token to consume, we peek at
// (but don't consume) the next token to decide how to set `*propType`.
//
// `=` or `;` ==> PropertyType::Field (classes only)
// `=` ==> PropertyType::CoverInitializedName
// `,` or `}` ==> PropertyType::Shorthand
// `(` ==> PropertyType::Method
// `=`, not in a class ==> PropertyType::CoverInitializedName
// '=', in a class ==> PropertyType::Field
// any token, in a class ==> PropertyType::Field (ASI)
//
// The caller must check `*propType` and throw if whatever we parsed isn't
// allowed here (for example, a getter in a destructuring pattern).
@ -10718,17 +10713,8 @@ Parser<ParseHandler>::propertyOrMethodName(YieldHandling yieldHandling,
return propName;
}
if (propertyNameContext == PropertyNameInClass && (tt == TOK_SEMI || tt == TOK_ASSIGN)) {
if (isGenerator || isAsync || isGetter || isSetter) {
error(JSMSG_BAD_PROP_ID);
return null();
}
tokenStream.ungetToken();
*propType = PropertyType::Field;
return propName;
}
if (TokenKindIsPossibleIdentifierName(ltok) &&
if (propertyNameContext != PropertyNameInClass &&
TokenKindIsPossibleIdentifierName(ltok) &&
(tt == TOK_COMMA || tt == TOK_RC || tt == TOK_ASSIGN))
{
if (isGenerator || isAsync || isGetter || isSetter) {
@ -10759,6 +10745,16 @@ Parser<ParseHandler>::propertyOrMethodName(YieldHandling yieldHandling,
return propName;
}
if (propertyNameContext == PropertyNameInClass) {
if (isGenerator || isAsync || isGetter || isSetter) {
error(JSMSG_BAD_PROP_ID);
return null();
}
tokenStream.ungetToken();
*propType = PropertyType::Field;
return propName;
}
error(JSMSG_COLON_AFTER_ID);
return null();
}

View file

@ -362,7 +362,6 @@ MSG_DEF(JSMSG_BAD_NEWTARGET, 0, JSEXN_SYNTAXERR, "new.target only allo
MSG_DEF(JSMSG_BAD_NEW_OPTIONAL, 0, JSEXN_SYNTAXERR, "new keyword cannot be used with an optional chain")
MSG_DEF(JSMSG_BAD_OPTIONAL_TEMPLATE, 0, JSEXN_SYNTAXERR, "tagged template cannot be used with optional chain")
MSG_DEF(JSMSG_ESCAPED_KEYWORD, 0, JSEXN_SYNTAXERR, "keywords must be written literally, without embedded escapes")
MSG_DEF(JSMSG_MISSING_SEMI_FIELD, 0, JSEXN_SYNTAXERR, "missing ; after field definition")
MSG_DEF(JSMSG_FIELDS_NOT_SUPPORTED, 0, JSEXN_SYNTAXERR, "fields are not currently supported")
// asm.js