summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorMartok <martok@martoks-place.de>2023-04-09 04:03:27 +0200
committerMartok <martok@martoks-place.de>2023-05-01 17:16:18 +0200
commitb35fadd54cea33569c2954df3c55c3f7dc7bd7b3 (patch)
tree6f13886d6c38893861d73b1013fb99a1532c60ce /js
parent0d3a394cad25be8e6acb6b8a249da3a809073fa2 (diff)
downloaduxp-b35fadd54cea33569c2954df3c55c3f7dc7bd7b3.tar.gz
Issue #2142 - Implement ASI for fields
Based-on: m-c 1529772/{3,4}
Diffstat (limited to 'js')
-rw-r--r--js/src/frontend/Parser.cpp36
-rw-r--r--js/src/js.msg1
2 files changed, 16 insertions, 21 deletions
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<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();
}
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