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

[preset-typescript] Fix private members type annotations #11315

Merged

Conversation

Lodin
Copy link
Contributor

@Lodin Lodin commented Mar 22, 2020

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

This PR fixes the bug when typescript transformer leaves type annotations for private properties. It does two main things:

  • Removes annotation for property that has initializer
  • Removes annotation and keeps private property declared if there is no initializer.
    class Foo {
      #bar: string;
    }
    By default typescript transformer removes such properties, but we need to preserve them according to the spec.
     class Foo {
      #bar;
     }

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented Mar 22, 2020

Ignore the CI failure, it is caused by an outdated base branch.

@nicolo-ribaudo nicolo-ribaudo added area: typescript PR: Bug Fix 🐛 A type of pull request used for our changelog categories labels Mar 22, 2020
@@ -325,13 +330,16 @@ export default declare(
// class transform would transform the class, causing more specific
// visitors to not run.
path.get("body.body").forEach(child => {
if (child.isClassMethod()) {
if (child.isClassMethod() || child.isClassPrivateMethod()) {
Copy link
Member

Choose a reason for hiding this comment

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

Note: this doesn't actually fix anything, but I'm ok with keeping it since we could add new things to the method handler, which could be also allowed with private methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I left it for consistency and for possible further changes

Copy link
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.

Thanks!

@nicolo-ribaudo nicolo-ribaudo merged commit 2f54988 into babel:master Mar 23, 2020
@Lodin Lodin deleted the fix/private-members-type-annotations branch March 23, 2020 19:40
@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 Jun 23, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: typescript 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[preset-typescript] Type annotations are not removed for private fields
4 participants