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

Define class elements in the correct order #12723

Merged
merged 5 commits into from Feb 2, 2021

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Jan 30, 2021

Q                       A
Fixed Issues? Fixes #4426, fixes #7156
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This PR fixes a few bugs with class elements coalescing:

  1. The original definition order is preserved
  2. Elements with the same computed key aren't merged together

@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories Spec: Classes labels Jan 30, 2021
@babel-bot
Copy link
Collaborator

babel-bot commented Jan 30, 2021

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 30, 2021

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 8c755f3:

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

let descriptor;
if (
!methods.hasComputed &&
t.isStringLiteral(key) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR, but we should also merge descriptors for NumericLiteral.

class C {
  set 0n(v) {}
  get 0n() {}
  set 1(v) {}
  get 1() {}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is new, so I can handle it here (they are merged with main).

// infer function name
if (node.kind === "method") {
fn = nameFunction({ id: key, node: node, scope });
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also infer the name of getters and setters, but I'll do that in a separate PR since it's not strictly related to this one.

@nicolo-ribaudo nicolo-ribaudo merged commit 60ef190 into babel:main Feb 2, 2021
@nicolo-ribaudo nicolo-ribaudo deleted the class-elements-order branch February 2, 2021 01:22
@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 May 4, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 4, 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: Classes
Projects
None yet
4 participants