-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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: handle block-level function declaration (#10046) #11801
Conversation
vitorveiga
commented
Jul 7, 2020
•
edited by gitpod-io
bot
Loading
edited by gitpod-io
bot
Q | A |
---|---|
Fixed Issues? | Fixes #10046, resolves #10050 |
Patch: Bug Fix? | Yes |
Major: Breaking Change? | No |
Minor: New Feature? | No |
Tests Added + Pass? | Yes |
Documentation PR Link | |
Any Dependency Changes? | No |
License | MIT |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 627fdcb:
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/32208/ |
Hello. @JLHwung did you have a chance to review this PR? Best Regards |
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.
I think it suffices to check if the following conditions are both true
.
binding.kind
is "hoisted"key
is not defined in parent scope
const binding = scope.getOwnBinding(key);
if (binding) {
if (binding.kind === "hoisted" && !scope.parent.hasOwnBinding(key)) {
continue;
}
scope.rename(ref.name);
}
The first condition is actually a shortcut for (binding && binding.path && !binding.path.isFunctionDeclaration())
. As of the second condition, we don't have to check isVar
because the fact that it is one of letRefs
implies there must be a let
/const
binding in current scope chain. Since the binding.kind
is "hoisted"
, it must be defined in upper scope so we can simply check whether an upper scope own a binding named as key
.
Thanks for your review :) Oh ok.. didn't know that The conditions were updated! |
Note that the renaming is nested in (You can also click on "Details" to see my implementation in #11801 (review)) |
Note that the implementation in #11801, fails on the unit-test issue-10046-collision-var due to the variable declaration on the program node. In that particular unit test, the
Maybe there is some implementation bug on letRefs map, but it seems that |
Hello @JLHwung did you have a chance to read my last comment? Thanks |
This PR caused some regressions: https://app.circleci.com/pipelines/github/babel/babel/4967/workflows/27043ada-f8d2-482e-810b-2593a17cf087/jobs/35381 |