Skip to content

Commit bf52dfc

Browse files
committed
[MERGE #5855 @pleath] Track assignments in some missing corner cases
Merge pull request #5855 from pleath:trackasg - Names on LHS of destructured assignment - LHS of for-of - "this" initialized by super()
2 parents f20fb03 + 34b8876 commit bf52dfc

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

lib/Parser/Parse.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -3297,6 +3297,9 @@ ParseNodePtr Parser::ParseTerm(BOOL fAllowCall,
32973297
// Super call needs to reference 'new.target'
32983298
if (pid == wellKnownPropertyPids._superConstructor)
32993299
{
3300+
// super() will write to "this", so track the assignment.
3301+
PidRefStack *thisRef = wellKnownPropertyPids._this->GetTopRef();
3302+
thisRef->isAsg = true;
33003303
ReferenceSpecialName(wellKnownPropertyPids._newTarget, ichMin, ichLim);
33013304
}
33023305

@@ -10287,7 +10290,9 @@ ParseNodePtr Parser::ParseStatement()
1028710290
}
1028810291
else
1028910292
{
10290-
pnodeT = ParseExpr<buildAST>(koplNo, &fCanAssign, /*fAllowIn = */FALSE);
10293+
IdentToken token;
10294+
pnodeT = ParseExpr<buildAST>(koplNo, &fCanAssign, /*fAllowIn = */FALSE, FALSE, NULL, nullptr, nullptr, &token);
10295+
TrackAssignment<buildAST>(pnodeT, &token);
1029110296
}
1029210297

1029310298
// We would veryfiy the grammar as destructuring grammar only when for..in/of case. As in the native for loop case the above ParseExpr call
@@ -12848,10 +12853,6 @@ ParseNodePtr Parser::ConvertArrayToArrayPattern(ParseNodePtr pnode)
1284812853
{
1284912854
*itemRef = ConvertObjectToObjectPattern(item);
1285012855
}
12851-
else if (item->nop == knopName)
12852-
{
12853-
TrackAssignment<true>(item, nullptr);
12854-
}
1285512856
});
1285612857

1285712858
return pnode;
@@ -12888,11 +12889,7 @@ ParseNodePtr Parser::GetRightSideNodeFromPattern(ParseNodePtr pnode)
1288812889
else
1288912890
{
1289012891
rightNode = pnode;
12891-
if (op == knopName)
12892-
{
12893-
TrackAssignment<true>(pnode, nullptr);
12894-
}
12895-
else if (op == knopAsg)
12892+
if (op == knopAsg)
1289612893
{
1289712894
TrackAssignment<true>(pnode->AsParseNodeBin()->pnode1, nullptr);
1289812895
}
@@ -13200,6 +13197,8 @@ ParseNodePtr Parser::ParseDestructuredVarDecl(tokens declarationType, bool isDec
1320013197
Error(ERRInvalidAssignmentTarget);
1320113198
}
1320213199

13200+
TrackAssignment<buildAST>(pnodeElem, &token);
13201+
1320313202
if (buildAST)
1320413203
{
1320513204
if (IsStrictMode() && pnodeElem != nullptr && pnodeElem->nop == knopName)

0 commit comments

Comments
 (0)