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

Using a set/get accessor causes a runtime error if the descriptor is not yet initialized #12905

Closed
dragomirtitian opened this issue Feb 25, 2021 · 1 comment · Fixed by #12918
Assignees
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue Spec: Private Methods

Comments

@dragomirtitian
Copy link

Bug Report

Current behavior
When accessing a get /set accessor before it's descriptor is created by the emitted code causes the error TypeError Cannot read property 'get' of undefined

REPL

Input Code

class AA {
  static #x = new AA();
  static get #y() { return 0; }
  static set #y(value) {  }
  constructor() {
    // Either will cause the error
    console.log(AA.#y);
    //AA.#y = 10 
  }
}

Expected behavior
This should work. It works in node.

Possible Solution
Reorder the emit to put private static accessors before fields. Accessor declarations do not have side effects so it is safe to execute them first. After, we can emit static fields, which can have side effects, safely, and any dependency on the static private accessors will work correctly.

@babel-bot
Copy link
Collaborator

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

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: Private Methods
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants