Issue #1658 - Part 1: Implement support for optional chaining in the JS Parser

Partially based on: https://bugzilla.mozilla.org/show_bug.cgi?id=1566143
This commit is contained in:
FranklinDM 2022-04-24 21:05:43 +08:00 committed by roytam1
commit e04a23ff98
10 changed files with 483 additions and 104 deletions

View file

@ -58,6 +58,7 @@ class SyntaxParseHandler
// in code not actually executed (or at least not executed enough to be
// noticed).
NodeFunctionCall,
NodeOptionalFunctionCall,
// Nodes representing *parenthesized* IsValidSimpleAssignmentTarget
// nodes. We can't simply treat all such parenthesized nodes
@ -78,7 +79,9 @@ class SyntaxParseHandler
NodeParenthesizedName,
NodeDottedProperty,
NodeOptionalDottedProperty,
NodeElement,
NodeOptionalElement,
// Destructuring target patterns can't be parenthesized: |([a]) = [3];|
// must be a syntax error. (We can't use NodeGeneric instead of these
@ -283,6 +286,7 @@ class SyntaxParseHandler
void addArrayElement(Node literal, Node element) { }
Node newCall() { return NodeFunctionCall; }
Node newOptionalCall() { return NodeOptionalFunctionCall; }
Node newTaggedTemplate() { return NodeGeneric; }
Node newObjectLiteral(uint32_t begin) { return NodeUnparenthesizedObject; }
@ -303,6 +307,7 @@ class SyntaxParseHandler
Node newYieldExpression(uint32_t begin, Node value) { return NodeGeneric; }
Node newYieldStarExpression(uint32_t begin, Node value) { return NodeGeneric; }
Node newAwaitExpression(uint32_t begin, Node value) { return NodeGeneric; }
Node newOptionalChain(uint32_t begin, Node value) { return NodeGeneric; }
// Statements
@ -353,8 +358,15 @@ class SyntaxParseHandler
return NodeDottedProperty;
}
Node newOptionalPropertyAccess(Node pn, PropertyName* name, uint32_t end) {
lastAtom = name;
return NodeOptionalDottedProperty;
}
Node newPropertyByValue(Node pn, Node kid, uint32_t end) { return NodeElement; }
Node newOptionalPropertyByValue(Node pn, Node kid, uint32_t end) { return NodeOptionalElement; }
MOZ_MUST_USE bool addCatchBlock(Node catchList, Node letBlock, Node catchName,
Node catchGuard, Node catchBody) { return true; }
@ -471,7 +483,8 @@ class SyntaxParseHandler
list == NodeUnparenthesizedCommaExpr ||
list == NodeVarDeclaration ||
list == NodeLexicalDeclaration ||
list == NodeFunctionCall);
list == NodeFunctionCall ||
list == NodeOptionalFunctionCall);
}
Node newAssignment(ParseNodeKind kind, Node lhs, Node rhs, JSOp op) {