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

Babel throws confusing error when private property is used as computed key #11414

Closed
1 task
JLHwung opened this issue Apr 13, 2020 · 3 comments · Fixed by #11571
Closed
1 task

Babel throws confusing error when private property is used as computed key #11414

JLHwung opened this issue Apr 13, 2020 · 3 comments · Fixed by #11571
Labels
i: enhancement outdated A closed issue/PR that is archived due to age. Recommended to make a new issue Spec: Class Fields

Comments

@JLHwung
Copy link
Contributor

JLHwung commented Apr 13, 2020

Bug Report

  • I would like to work on a fix!

Current Behavior
The following snippet, after transformed, throws

Cannot read property 'get' of undefined

Input Code

class Toggle {
  #prop = "disabled";
  [this.#prop] = false
}

Expected behavior/code
It should throw

attempted to get private field on non-instance

Environment
REPL

Possible Solution

We should also check if privateMap is undefined in

export default function _classPrivateFieldGet(receiver, privateMap) {

Additional context/Screenshots
Found this issue when reviewing PR 11405.

@babel-bot
Copy link
Collaborator

Hey @JLHwung! 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."

@jridgewell
Copy link
Member

jridgewell commented Apr 14, 2020

Once #11405 has landed, this will be a very simple fix. All that's needed is to rearrange https://github.com/babel/babel/blob/070ec201/packages/babel-helper-create-class-features-plugin/src/index.js#L185-L186, so that the private name nodes are inserted before the key nodes.

I think this is a GFI.

@AjayPoshak
Copy link
Contributor

I would like to take it up.

@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 Aug 30, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: enhancement 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.

4 participants