Skip to content

improve helper-create-class-features typings#14530

Merged
nicolo-ribaudo merged 4 commits intobabel:mainfrom
JLHwung:improve-helper-create-class-features-typings
May 17, 2022
Merged

improve helper-create-class-features typings#14530
nicolo-ribaudo merged 4 commits intobabel:mainfrom
JLHwung:improve-helper-create-class-features-typings

Conversation

@JLHwung
Copy link
Copy Markdown
Contributor

@JLHwung JLHwung commented May 5, 2022

Q                       A
Fixed Issues? Throw an error when class auto accessors are used with 2018-09 decorators
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Improved helper-create-class-features typings. The type-checker found a bug that we didn't take into account some class members in the 2018-09 decorator transform.

if (state.classRef?.name && state.classRef.name !== innerBindingRef?.name) {
// todo: use innerBinding.referencePaths to avoid full traversal
if (
innerBindingRef != null &&
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented May 5, 2022

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

@JLHwung JLHwung force-pushed the improve-helper-create-class-features-typings branch from 6dd28a7 to 3179cb8 Compare May 5, 2022 19:38
>;

function getKey(node: SupportedElement) {
if (node.type === "StaticBlock") {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe we should throw plugin ordering errors for StaticBlock seen here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems to be broken regardless of the plugin ordering, when using this test:

const code = `
@dec
class A {
  static {
    x = 2;
  }
}
`;

const out = babel.transformSync(code, {
  configFile: false,
  plugins: [
    [
      require("@babel/plugin-proposal-decorators"),
      { version: "2018-09", decoratorsBeforeExport: true },
    ],
    require("@babel/plugin-proposal-class-static-block"),
  ],
});

in main it throws; with this PR it discards the static block. Lets keep this PR as internal-only, but that bug should then be fixed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if (node.type === "StaticBlock") {
if (node.type === "StaticBlock") {
// TODO: Fix compatibility between 2018-09 decorators and static blocks

Copy link
Copy Markdown
Member

@nicolo-ribaudo nicolo-ribaudo May 17, 2022

Choose a reason for hiding this comment

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

Ok actually, let's just add an error as you did for accessor properties. If someone wants to use static blocks they can upgrade their code to use the new decorators proposal.

@JLHwung JLHwung force-pushed the improve-helper-create-class-features-typings branch 2 times, most recently from f7fdbfe to 8fc721d Compare May 9, 2022 19:14
@JLHwung JLHwung force-pushed the improve-helper-create-class-features-typings branch from 8fc721d to e8f4543 Compare May 11, 2022 18:46
Copy link
Copy Markdown
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

We can merge this with a single ✔️, since the changes are almost only related to type annotations (and the other changes are very minor refactors just to help TS).

@existentialism existentialism added the PR: Internal 🏠 A type of pull request used for our changelog categories label May 17, 2022
@nicolo-ribaudo nicolo-ribaudo merged commit 4d12808 into babel:main May 17, 2022
@nicolo-ribaudo nicolo-ribaudo deleted the improve-helper-create-class-features-typings branch May 17, 2022 15:59
@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 17, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 17, 2022
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: Internal 🏠 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants