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); return node->isKind(PNK_NAME);
} }
bool isPrivateName(Node node) {
return node->isKind(PNK_NAME) && node->as<NameNode>().isPrivateName();
}
bool isArgumentsAnyParentheses(Node node, ExclusiveContext* cx) { bool isArgumentsAnyParentheses(Node node, ExclusiveContext* cx) {
return node->isKind(PNK_NAME) && node->as<NameNode>().atom() == cx->names().arguments; return node->isKind(PNK_NAME) && node->as<NameNode>().atom() == cx->names().arguments;
} }

View file

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

View file

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