Allow mixing private destructuring and rest#17534
Merged
nicolo-ribaudo merged 9 commits intobabel:mainfrom Oct 17, 2025
Merged
Conversation
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/60059 |
|
commit: |
JLHwung
reviewed
Oct 13, 2025
Contributor
JLHwung
left a comment
There was a problem hiding this comment.
Thank you for your contribution. This PR looks good to me generally, pending literal checks in the duplicate keys detection.
| propertyKey.type === "Identifier" | ||
| ) { | ||
| return existing.key.name === propertyKey.name; | ||
| } |
Contributor
There was a problem hiding this comment.
Nit: A literal property name can also be one of
- string literal (
"0") - numerical literal (
0) - bigint literal (
0n)
To optimize the output, we should also check these AST types for potential duplicates.
Contributor
Author
There was a problem hiding this comment.
@JLHwung
Thanks for review.
I've added the checks for the types you mentioned.
Are there any other types or edge cases I should consider?
JLHwung
approved these changes
Oct 13, 2025
Contributor
JLHwung
left a comment
There was a problem hiding this comment.
Thank you! This PR now looks very good and I don't have more comments.
JLHwung
reviewed
Oct 13, 2025
remark: add tc39 link Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
This was referenced Oct 23, 2025
This was referenced Nov 27, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a bug in @babel/plugin-proposal-destructuring-private where explicit properties after a private key were destructured from an already-excluded object, causing values to become undefined.
What changed
Split post-private segment into two declarators:
bind explicit props (e.g.
{ a: x };In Issue example) from the original RHS (C)bind only the rest identifier from objectWithoutProperties(RHS, excluded)
Grow excludingKeys before emitting explicit props so rest properly excludes them.
Memoize non-static computed keys during excludingKeys growth (e.g. [_m = a()]) so the same key is reused by both explicit and rest parts (single evaluation).
Dedupe non-computed keys (Identifier, StringLiteral, NumericLiteral, BigIntLiteral)