You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functiona(){functionb(){use(x);/* x no longer refers to the same let binding */}if(!foo){letx=1;// dead code}}
Options are
Detect block scoped binding usages and deopt if_return transformation (since this transformation itself causes changes in block, and we have a babel issue with bindings and scopes, it MIGHT lead to other issues with bindings or detection)
Hoist let declaration: Cannot have const, and also here, we'll suppress a possible error by doing this as let is not hoisted.
functiona(){if(foo)return;use(x);// here it will throw as x is not yet a binding and let is not hoistedletx=1;functionb(){use(x)};}
to
functiona(){functionb(){use(x);}letx;if(!foo){use(x);// here x is a binding and is undefinedx=1;}}
@hzoo True. But the only thing that's blocking is some bugs in babel's scope tracking - we solved most of these issues (in mangler and dce) - by doing traverse.clearCache() and scope.crawl(). We cannot do that in simplify, and we don't want simplify to be a single pass.
Edit:
Also, we have to change node.field = newField style to path.replaceWith as mutation doesn't update scope tracking and it's possible to insert a faulty node with mutating the node directly through assignment.
Activity
boopathi commentedon Feb 1, 2017
Some bug with if..return transform
boopathi commentedon Feb 1, 2017
Related #281
boopathi commentedon Feb 1, 2017
Fix for #281 and fix for this one feels like
[-][DCE] Bug: Removes something it shouldn't[/-][+]If..return removes something it shouldn't[/+]boopathi commentedon Feb 3, 2017
/cc @kangax @hzoo
Need some suggestions to handle this -
cannot be transformed to (which is happening now)
Options are
letdeclaration: Cannot haveconst, and also here, we'll suppress a possible error by doing this asletis not hoisted.to
Any other ideas or suggestions welcome.
ziadkh0 commentedon Feb 3, 2017
@boopathi Why not wrap the whole thing with the
if?boopathi commentedon Feb 3, 2017
@zaygraveyard
hzoo commentedon Feb 3, 2017
I think it's best for us to deopt when possible and then go back and do optimizations? I think our goal is stability first, opt later?
It is safe for us to hoist let/anything?
boopathi commentedon Feb 3, 2017
@hzoo True. But the only thing that's blocking is some bugs in babel's scope tracking - we solved most of these issues (in mangler and dce) - by doing
traverse.clearCache()andscope.crawl(). We cannot do that insimplify, and we don't want simplify to be a single pass.Edit:
Also, we have to change
node.field = newFieldstyle topath.replaceWithas mutation doesn't update scope tracking and it's possible to insert a faulty node with mutating the node directly through assignment.if_return - deopt when ref loses scope - fix #399
if_return - deopt when ref loses scope - fix #399
if_return - deopt when ref loses scope (#408)