Skip to content
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

Inject IIFE when variables shadow binding in rest param #14736

Merged

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Jul 7, 2022

Q                       A
Fixed Issues? Fixes #14156, closes #14215
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This is an alternative to #14215, which takes a completely different approach (sorry @The-x-Theorist, I was reviewing&rebasing your PR, and thanks to TS I noticed that the case of "nested bindings" had not been considered 😅)

We already had the logic to handle shadowed function parameters in destructuring/defaults, and this PR re-uses it also for rest params.

@nicolo-ribaudo nicolo-ribaudo added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Jul 7, 2022
@babel-bot
Copy link
Collaborator

babel-bot commented Jul 7, 2022

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/52453/

console.log(Object.keys(t.getBindingIdentifiers(pattern)));

Copy link
Contributor

@JLHwung JLHwung Jul 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log(Object.keys(t.getBindingIdentifiers(pattern)));

);
}
}

let rest = (node.params.pop() as t.RestElement).argument as
Copy link
Contributor

@JLHwung JLHwung Jul 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: does rest always equal to restPath.node?

Copy link
Member Author

@nicolo-ribaudo nicolo-ribaudo Jul 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I simplified the code and added a comment in the last commit 👍

JLHwung
JLHwung approved these changes Jul 7, 2022
@nicolo-ribaudo nicolo-ribaudo force-pushed the fix-param-name-conflicts-in-rest branch from 7b2108c to df261c0 Compare Jul 8, 2022
@nicolo-ribaudo nicolo-ribaudo merged commit f2347e4 into babel:main Jul 8, 2022
35 checks passed
@nicolo-ribaudo nicolo-ribaudo deleted the fix-param-name-conflicts-in-rest branch Jul 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants