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

Generate class ref ID for anonymous class only #12403

Closed
wants to merge 2 commits into from

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Nov 26, 2020

Q                       A
Fixed Issues? Fixes #11990
Patch: Bug Fix? Y
Tests Added + Pass? Yes
License MIT

A named class expression can be referenced in the field initializers, e.g.

const x = class B {
  static b = B.name
}

before this PR we generated _class reference to B but did not replace B.name to _class.name.

const x = (_temp = _class = class B {}, _defineProperty(_class, "b", B.name), _temp);

I assume that we are safe to produce (X = class X {}) as the following cases are invalid

(a) => { a = 1; return class a {} };
const a = class a {};

so this PR clones the class binding identifier when it exists, since it could be referenced in field initializers.

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories Spec: Class Fields labels Nov 26, 2020
@babel-bot
Copy link
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/33306/

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit dc3a666:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@nicolo-ribaudo
Copy link
Member

I assume that we are safe to produce (X = class X {}) as the following cases are invalid

(a) => { a = 1; return class a {} };
const a = class a {};

Are you sure? I think both are valid (at least, they work in Chrome)

@JLHwung
Copy link
Contributor Author

JLHwung commented Nov 26, 2020

@nicolo-ribaudo Ah I probably mess up a bit in the devtools. Closing this as this approach will introduce new issues.

@JLHwung JLHwung closed this Nov 26, 2020
@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 Feb 26, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 26, 2021
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 Spec: Class Fields
Projects
None yet
Development

Successfully merging this pull request may close these issues.

referenced static property in class instance throws ReferenceError
3 participants