Skip to content

Define class elements in the correct order#12723

Merged
nicolo-ribaudo merged 5 commits intobabel:mainfrom
nicolo-ribaudo:class-elements-order
Feb 2, 2021
Merged

Define class elements in the correct order#12723
nicolo-ribaudo merged 5 commits intobabel:mainfrom
nicolo-ribaudo:class-elements-order

Conversation

@nicolo-ribaudo
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Development

Successfully merging this pull request may close these issues.

Computed accessor pairs shouldn't be merged Order of method and getter/setter definition not honored in class declaration (T7527)

4 participants