Issue #2142 - Implement syntax for public/private fields and computed field names

This state still has the initializers scoped on .initializers local variable, which will be changed later.

Based-on: m-c 1499448, 1530084, 1530832, 1529448 (partial), 1532921, 1528039, 1528038, 1535166, 1550628,
              1535166, 1550628, 1541641, 1547133, 1540787, 1535804/9
This commit is contained in:
Martok 2023-04-06 03:10:50 +02:00 committed by roytam1
commit 51db22ff2f
24 changed files with 1383 additions and 290 deletions

View file

@ -92,6 +92,8 @@ enum class InvalidEscapeType {
Octal
};
enum class NameVisibility { Public, Private };
class TokenStream;
struct Token
@ -185,7 +187,7 @@ struct Token
// Mutators
void setName(PropertyName* name) {
MOZ_ASSERT(type == TOK_NAME);
MOZ_ASSERT(type == TOK_NAME || type == TOK_PRIVATE_NAME);
u.name = name;
}
@ -211,7 +213,7 @@ struct Token
// Type-safe accessors
PropertyName* name() const {
MOZ_ASSERT(type == TOK_NAME);
MOZ_ASSERT(type == TOK_NAME || type == TOK_PRIVATE_NAME);
return u.name->JSAtom::asPropertyName(); // poor-man's type verification
}
@ -344,7 +346,7 @@ class MOZ_STACK_CLASS TokenStream
public:
PropertyName* currentName() const {
if (isCurrentTokenType(TOK_NAME)) {
if (isCurrentTokenType(TOK_NAME) || isCurrentTokenType(TOK_PRIVATE_NAME)) {
return currentToken().name();
}
@ -353,7 +355,7 @@ class MOZ_STACK_CLASS TokenStream
}
bool currentNameHasEscapes() const {
if (isCurrentTokenType(TOK_NAME)) {
if (isCurrentTokenType(TOK_NAME) || isCurrentTokenType(TOK_PRIVATE_NAME)) {
TokenPos pos = currentToken().pos;
return (pos.end - pos.begin) != currentToken().name()->length();
}