Issue #2298 - Carry private-ness of names through ParseNodeHandler

This commit is contained in:
Martok 2023-08-29 22:58:21 +02:00 committed by roytam1
commit b0d9f0e2ed
3 changed files with 19 additions and 1 deletions

View file

@ -965,6 +965,10 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_AS)
return node->isKind(PNK_NAME);
}
bool isPrivateName(Node node) {
return node->isKind(PNK_NAME) && node->as<NameNode>().isPrivateName();
}
bool isArgumentsAnyParentheses(Node node, ExclusiveContext* cx) {
return node->isKind(PNK_NAME) && node->as<NameNode>().atom() == cx->names().arguments;
}

View file

@ -953,6 +953,10 @@ class NameNode : public ParseNode
JSAtom* atom() const {
return pn_u.name.atom;
}
bool isPrivateName() const {
return atom()->asPropertyName()->latin1OrTwoByteChar(0) == '#';
}
ParseNode* initializer() const {
return pn_u.name.initOrStmt;

View file

@ -104,6 +104,9 @@ class SyntaxParseHandler
// Node representing the "async" name, which may actually be a
// contextual keyword.
NodePotentialAsyncKeyword,
// Node representing a private name. Handled mostly like NodeUnparenthesizedName.
NodePrivateName,
// Valuable for recognizing potential destructuring patterns.
NodeUnparenthesizedArray,
@ -212,6 +215,8 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_AS)
return NodePotentialAsyncKeyword;
if (name == cx->names().eval)
return NodeUnparenthesizedEvalName;
if (name->length() >= 1 && name->latin1OrTwoByteChar(0) == '#')
return NodePrivateName;
return NodeUnparenthesizedName;
}
@ -614,7 +619,8 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_AS)
return node == NodeUnparenthesizedArgumentsName ||
node == NodeUnparenthesizedEvalName ||
node == NodeUnparenthesizedName ||
node == NodePotentialAsyncKeyword;
node == NodePotentialAsyncKeyword ||
node == NodePrivateName;
}
bool isNameAnyParentheses(Node node) {
@ -625,6 +631,10 @@ FOR_EACH_PARSENODE_SUBCLASS(DECLARE_AS)
node == NodeParenthesizedName;
}
bool isPrivateName(Node node) {
return node == NodePrivateName;
}
bool isArgumentsAnyParentheses(Node node, ExclusiveContext* cx) {
return node == NodeUnparenthesizedArgumentsName || node == NodeParenthesizedArgumentsName;
}