-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add support for logical assignment operator #6663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -281,6 +281,9 @@ LPCWSTR Parser::GetTokenString(tokens token) | |
case tkLogOr: return _u("||"); | ||
case tkLogAnd: return _u("&&"); | ||
case tkCoalesce: return _u("??"); | ||
case tkAsgLogOr: return _u("||="); | ||
case tkAsgLogAnd: return _u("&&="); | ||
case tkAsgLogCoalesce: return _u("??="); | ||
case tkOr: return _u("|"); | ||
case tkXor: return _u("^"); | ||
case tkAnd: return _u("&"); | ||
|
@@ -12748,6 +12751,9 @@ ParseNode* Parser::CopyPnode(ParseNode *pnode) { | |
case knopLogOr: | ||
case knopLogAnd: | ||
case knopCoalesce: | ||
case knopAsgLogAnd: | ||
case knopAsgLogOr: | ||
case knopAsgCoalesce: | ||
case knopLsh: | ||
case knopRsh: | ||
case knopRs2: | ||
|
@@ -14042,6 +14048,21 @@ void PrintPnodeWIndent(ParseNode *pnode, int indentAmt) { | |
PrintPnodeWIndent(pnode->AsParseNodeBin()->pnode1, indentAmt + INDENT_SIZE); | ||
PrintPnodeWIndent(pnode->AsParseNodeBin()->pnode2, indentAmt + INDENT_SIZE); | ||
break; | ||
case knopAsgLogAnd: | ||
Indent(indentAmt); | ||
Output::Print(_u("&&=\n")); | ||
PrintPnodeWIndent(pnode->AsParseNodeBin()->pnode1, indentAmt + INDENT_SIZE); | ||
PrintPnodeWIndent(pnode->AsParseNodeBin()->pnode2, indentAmt + INDENT_SIZE); | ||
case knopAsgLogOr: | ||
Indent(indentAmt); | ||
Output::Print(_u("||=\n")); | ||
PrintPnodeWIndent(pnode->AsParseNodeBin()->pnode1, indentAmt + INDENT_SIZE); | ||
PrintPnodeWIndent(pnode->AsParseNodeBin()->pnode2, indentAmt + INDENT_SIZE); | ||
case knopAsgCoalesce: | ||
Indent(indentAmt); | ||
Output::Print(_u("??=\n")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ubuntu sees "??=" as a trigraph (a weird obsolete C language feature) to stop the compile failures I think you'll need to change this to "??=" |
||
PrintPnodeWIndent(pnode->AsParseNodeBin()->pnode1, indentAmt + INDENT_SIZE); | ||
PrintPnodeWIndent(pnode->AsParseNodeBin()->pnode2, indentAmt + INDENT_SIZE); | ||
//PTNODE(knopLsh , "<<" ,Lsh ,Bin ,fnopBin) | ||
case knopLsh: | ||
Indent(indentAmt); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1778,7 +1778,20 @@ tokens Scanner<EncodingPolicy>::ScanCore(bool identifyKwds) | |
{ | ||
p++; | ||
token = tkCoalesce; | ||
break; | ||
} | ||
if (m_scriptContext->GetConfig()->IsEsLogicalAssignmentOperatorEnabled()) | ||
{ | ||
Assert(token == tkQMark || token == tkCoalesce); | ||
if (token == tkCoalesce && this->PeekFirst(p, last) == '=') | ||
{ | ||
p++; | ||
token = tkAsgLogCoalesce; | ||
} | ||
else if (this->PeekFirst(p, last) == '?' && this->PeekFirst(p + 1, last) == '=') | ||
{ | ||
p += 2; | ||
token = tkAsgLogCoalesce; | ||
} | ||
Comment on lines
+1790
to
+1794
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this case only possible if NullishCoalescing is disabled? If yes please include a comment about that. |
||
} | ||
break; | ||
|
||
|
@@ -2181,6 +2194,12 @@ tokens Scanner<EncodingPolicy>::ScanCore(bool identifyKwds) | |
case '|': | ||
p++; | ||
token = tkLogOr; | ||
if (m_scriptContext->GetConfig()->IsEsLogicalAssignmentOperatorEnabled() && this->PeekFirst(p, last) == '=') | ||
{ | ||
p++; | ||
token = tkAsgLogOr; | ||
break; | ||
} | ||
break; | ||
} | ||
break; | ||
|
@@ -2196,6 +2215,12 @@ tokens Scanner<EncodingPolicy>::ScanCore(bool identifyKwds) | |
case '&': | ||
p++; | ||
token = tkLogAnd; | ||
if (m_scriptContext->GetConfig()->IsEsLogicalAssignmentOperatorEnabled() && this->PeekFirst(p, last) == '=') | ||
{ | ||
p++; | ||
token = tkAsgLogAnd; | ||
break; | ||
} | ||
break; | ||
} | ||
break; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please can you revert these whitespace changes; the large gaps are intentional; the idea is to show the descriptions of related fields in line with each other - it's not been done perfectly but would rather keep it.