From b35fadd54cea33569c2954df3c55c3f7dc7bd7b3 Mon Sep 17 00:00:00 2001 From: Martok Date: Sun, 9 Apr 2023 04:03:27 +0200 Subject: Issue #2142 - Implement ASI for fields Based-on: m-c 1529772/{3,4} --- js/src/frontend/Parser.cpp | 36 ++++++++++++++++-------------------- js/src/js.msg | 1 - 2 files changed, 16 insertions(+), 21 deletions(-) (limited to 'js') diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index aa0e005268..d184ae956a 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -7485,13 +7485,7 @@ Parser::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::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::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::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(); } diff --git a/js/src/js.msg b/js/src/js.msg index 8e08e213db..2cae3ff125 100644 --- a/js/src/js.msg +++ b/js/src/js.msg @@ -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 -- cgit v1.2.3