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

Fix destructuring with holes in assign pattern #14240

Merged
merged 4 commits into from Feb 11, 2022
Merged

Fix destructuring with holes in assign pattern #14240

merged 4 commits into from Feb 11, 2022

Conversation

magic-akari
Copy link
Contributor

@magic-akari magic-akari commented Feb 4, 2022

  • fix const assign pattern
  • optimize the output of let/var assign pattern
Q                       A
Fixed Issues? Fixes #14239
Patch: Bug Fix? 👍
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

- fix `const` assign pattern
- optimize the output of `let`/`var` assign pattern
Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

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

I think we should fix the issue in pushUnpackedArrayPattern, so we can handle other patterns:

const [...x] = [,];
const [...{0: x}] = [,];

@magic-akari
Copy link
Contributor Author

It seems Babel has handled it well.

REPL

const [...x] = [,];
const [...{ 0: y }] = [,];
const x = [,];
const y = [,][0];

@JLHwung
Copy link
Contributor

JLHwung commented Feb 9, 2022

Could you check if const [x] = [,]; is now transformed?

@magic-akari
Copy link
Contributor Author

Could you check if const [x] = [,]; is now transformed?

I tested it locally. It behaves as same as the REPL.

const x;

It is indeed a bug related to this Pull Request.

But I don't have a clear idea about how to fix it.

For the test case like following

const [ x = 1 ] = [,];

I am sure that const x = 1; is the best transformed output.

But for const [x] = [,], if we give it a value like

const x = void 0;

Meanwhile we will get void 0 when transformed to es5

var x = void 0;

The void 0 seems to be redundant for the "var" declaration.

What do you think about it? @JLHwung

@JLHwung
Copy link
Contributor

JLHwung commented Feb 9, 2022

@magic-akari

const x = void 0;

looks good to me. As a transpiler we should support valid language usage. The example above could be further transpiled into var x, but that should be addressed by the transform-block-scoping.

Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

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

Thanks!

@magic-akari magic-akari marked this pull request as draft February 10, 2022 02:41
@magic-akari
Copy link
Contributor Author

magic-akari commented Feb 10, 2022

Thanks!

Sorry, not finished.

@magic-akari magic-akari marked this pull request as ready for review February 10, 2022 02:44
@magic-akari
Copy link
Contributor Author

I think it's ready now.

@nicolo-ribaudo nicolo-ribaudo added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Feb 11, 2022
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

Thanks!

@nicolo-ribaudo nicolo-ribaudo changed the title Fix destructuring with hole in assign pattern Fix destructuring with holes in assign pattern Feb 11, 2022
@nicolo-ribaudo nicolo-ribaudo merged commit 6b4d466 into babel:main Feb 11, 2022
JLHwung added a commit to JLHwung/babel that referenced this pull request Feb 11, 2022
JLHwung added a commit to JLHwung/babel that referenced this pull request Feb 18, 2022
JLHwung added a commit to JLHwung/babel that referenced this pull request Feb 23, 2022
JLHwung added a commit to JLHwung/babel that referenced this pull request Feb 28, 2022
JLHwung added a commit that referenced this pull request Mar 7, 2022
* refactor: extract destructuring transform routines

* improve destructuring plugin typings

* refactor: replace Record<string, boolean> to set

* review comments

* apply #14240 fix

* fix: Babel should not crash when destructring arrray hole

* make node 8 happy

* refactor: extract buildObjectExcludingKeys
@magic-akari magic-akari deleted the fix/issue-14239 branch March 8, 2022 06:11
@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 Jun 8, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 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]: unexpected error when attempting to destructure initializer with a "hole"
3 participants