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/

Comment on lines 336 to 337
console.log(Object.keys(t.getBindingIdentifiers(pattern)));

Copy link
Contributor

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

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

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 👍

@nicolo-ribaudo nicolo-ribaudo force-pushed the fix-param-name-conflicts-in-rest branch from 7b2108c to df261c0 Compare July 8, 2022 07:33
@nicolo-ribaudo nicolo-ribaudo merged commit f2347e4 into babel:main Jul 8, 2022
@nicolo-ribaudo nicolo-ribaudo deleted the fix-param-name-conflicts-in-rest branch July 8, 2022 07:46
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 8, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue 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.

[Bug]: rest args and deconstruction, error.
4 participants