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

bug: exception with destructuring assignment with private fields #9310

Closed
dnalborczyk opened this issue Jan 10, 2019 · 4 comments · Fixed by #10017
Closed

bug: exception with destructuring assignment with private fields #9310

dnalborczyk opened this issue Jan 10, 2019 · 4 comments · Fixed by #10017
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue Spec: Class Fields

Comments

@dnalborczyk
Copy link
Contributor

dnalborczyk commented Jan 10, 2019

Bug Report

Current Behavior
Invalid destructuring assignment target exception with destructuring assignment with private fields

Input Code

class Foo {
  #client

  constructor(props) {
    ;({ client: this.#client } = props) // throws: Invalid destructuring assignment target
  }
}

transpiles to (excerpt):

({
  client: _classPrivateFieldGet(this, _client)  // notice the getter
} = props);

Environment

  • Babel version: v7.2.2

update:

I suppose it would need to use _classPrivateFieldSet as well as transpile the ES2015 destructuring assignment? unless destructuring assignments work with a function call ... which I don't think it does?

var client = props.client
_classPrivateFieldSet(this, _client, client);

for what it's worth: works in node --harmony v11.6.0

@babel-bot
Copy link
Collaborator

Hey @dnalborczyk! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community
that typically always has someone willing to help. You can sign-up here
for an invite.

@nicolo-ribaudo
Copy link
Member

We should transpile it by moving the private assignment after the destructuring.

@dnalborczyk
Copy link
Contributor Author

then you'd need to rename the instance private field inside the destructuring to local scope as well I suppose?

({ client: this.#client } = props)

becomes something like ...

var _client
({ client: _client } = props)
_classPrivateFieldSet(this, _client, client)

@nicolo-ribaudo
Copy link
Member

Yes 👍

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 13, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue Spec: Class Fields
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants