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

Open
dnalborczyk opened this Issue Jan 10, 2019 · 4 comments

Comments

Projects
None yet
3 participants
@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

This comment has been minimized.

Copy link
Collaborator

babel-bot commented Jan 10, 2019

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

This comment has been minimized.

Copy link
Member

nicolo-ribaudo commented Jan 10, 2019

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

@dnalborczyk

This comment has been minimized.

Copy link
Contributor

dnalborczyk commented Jan 10, 2019

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

This comment has been minimized.

Copy link
Member

nicolo-ribaudo commented Jan 10, 2019

Yes 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment