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

Can not enable syntax-class-properties with other fields related plugins #12691

Open
1 task
JounQin opened this issue Jan 26, 2021 · 7 comments
Open
1 task

Comments

@JounQin
Copy link
Contributor

JounQin commented Jan 26, 2021

Bug Report

  • I would like to work on a fix!

Current behavior

Input Code

export class Foo {
  #bar = 'bar'
}

Expected behavior

I'd like to keep class properties as-is.

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: babel.config.js
module.exports = {
  plugins: [
    '@babel/syntax-class-properties',
    '@babel/proposal-private-methods',
  ],
}

Environment

- Babel version(s): v7.12.10
- Node/npm version: Node v12.20.0/npm 6.14.9
- OS: macOS 11.2 Beta
- Monorepo: no
- How you are using Babel: API directly

Possible Solution

Check syntax-class-properties instead of proposal-class-properties for class fields

Additional context

@babel-bot
Copy link
Collaborator

Hey @JounQin! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

@fedeci
Copy link
Member

fedeci commented Jan 26, 2021

I think we should check if the property is private here, like we do for methods.

if (path.isProperty()) {
if (!hasFeature(file, FEATURES.fields)) {
throw path.buildCodeFrameError("Class fields are not enabled.");
}
}
}

@JounQin
Copy link
Contributor Author

JounQin commented Jan 26, 2021

@fedeci

class-static-block and private-property-in-object are both affected too.

@fedeci
Copy link
Member

fedeci commented Jan 26, 2021

@JounQin Cannot reproduce those😕

@JounQin
Copy link
Contributor Author

JounQin commented Jan 26, 2021

@fedeci Sorry my fault, private-property-in-object is affected but not class-static-block.

REPL

@nicolo-ribaudo
Copy link
Member

This is probably fixed by part of #12250, I can split that PR in two separate PRs.

@nicolo-ribaudo
Copy link
Member

I'm preparing #13260 as an alternative for #12250, which gives better and easier control on how the different class features transforms interact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants