Skip to content

Commit 68d19b7

Browse files
committed
[MERGE #5853 @boingoing] Special symbol var decls can be created in the wrong function
Merge pull request #5853 from boingoing:function_id_with_destructured_reparse When we rollback the scanner and reparse a destructured object literal containing a function and the outer funtion has a special symbol reference, it is possible we will incorrectly create a var decl for the special symbol in the nested function.
2 parents 4b4d4a2 + 5016ff3 commit 68d19b7

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

lib/Parser/Parse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,7 @@ ParseNodeVar * Parser::CreateSpecialVarDeclIfNeeded(ParseNodeFnc * pnodeFnc, Ide
17411741
PidRefStack* ref = pid->GetTopRef();
17421742

17431743
// If the function has a reference to pid or we set forceCreate, make a special var decl
1744-
if (forceCreate || (ref && ref->GetScopeId() >= m_currentBlockInfo->pnodeBlock->blockId))
1744+
if (forceCreate || (ref && (ref->GetScopeId() >= m_currentBlockInfo->pnodeBlock->blockId && ref->GetFuncScopeId() >= pnodeFnc->functionId)))
17451745
{
17461746
return this->CreateSpecialVarDeclNode(pnodeFnc, pid);
17471747
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
function test0() {
7+
({
8+
p: o = ({
9+
bar() {
10+
(function () {})
11+
}
12+
},
13+
(this))
14+
} = 0)
15+
}
16+
test0()
17+
18+
console.log('pass');

test/Bugs/rlexe.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,13 @@
551551
<tags>exclude_jshost</tags>
552552
</default>
553553
</test>
554+
<test>
555+
<default>
556+
<files>function_id_destructured_reparse.js</files>
557+
<compile-flags>-useparserstatecache -parserstatecache -force:deferparse</compile-flags>
558+
<tags>exclude_jshost</tags>
559+
</default>
560+
</test>
554561
<test>
555562
<default>
556563
<files>bug_5585.js</files>

0 commit comments

Comments
 (0)