-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix hoisting of arguments #283
Conversation
I'm not an expert on how hoisting works in Babel, though I have encountered it before. If anyone else has immediate ideas, please do chime in! |
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.
This explanation of _shadowedFunctionLiteral
seems consistent with the intent of these changes.
Is this possibly related to gaearon/react-hot-loader#391 / babel/babel#5078 ? |
I was thinking the same that there is probably the same issue with this. But this PR is only for arguments. Maybe I can figure out if we can do the same with this. @benjamn yeah it is weird that we have to use a private flag, but not sure what else we should do in this case, maybe we can disable the hoisting in a better way, I will investigate a little more. |
@Kovensky The Another idea I had was turning the function into a non shadowed function by doing Anyone has a different idea? |
@danez Care to add a test for this behavior, just in case the |
If you tell me how. All the tests seem to require native support in node for the features being tested, which might be hard here for |
Sure, the |
Thanks for the help, hope it is okay they way I setup the test. |
In the case that the generator or the async function is initially an arrow function and uses only a rest param, the babel es2015 transforms will replace the arrow with a function and the rest param with arguments. regenerator-transform will later also replace and move the arguments. In the end babel will hoist the arguments back up, but to the wrong level.
Thats a little bit complicated to describe, maybe better I show it with code:
This change sets a hint on the
arguments
-identifier to which function it belongs to, and it will only get hoisted up to this level.We also do this in babel in certain places: https://github.com/babel/babel/blob/7.0/packages/babel-plugin-transform-es2015-parameters/src/rest.js#L212
I tried creating an test, but couldn't find exactly how to do it.
//cc @hzoo @existentialism @loganfsmyth
Fixes: babel/babel#5485 babel/babel#5330 babel/babel#4219