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

Include @babel/plugin-proposal-class-properties in @babel/preset-typescript #12030

Closed
dilyanpalauzov opened this issue Sep 3, 2020 · 3 comments · Fixed by babel/website#2399
Labels
i: question outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@dilyanpalauzov
Copy link

I want to use Babel 7.11.5 only to strip TypeScript declarations, as fast alternative to running tsc. With X.ts:

class X {
    #y(n: number) {
      console.log(n + 2);
    }
}

This fails:

babel --presets @babel/preset-typescript --extensions '.ts' X.ts
SyntaxError: X.ts: Support for the experimental syntax 'classPrivateProperties' isn't currently enabled (2:5):

  1 | class X {
> 2 |     #y(n: number) {
    |     ^
  3 |       console.log( n + 2);
  4 |     }
  5 | }

Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins' section of your Babel config to enable transformation.
If you want to leave it as-is, add @babel/plugin-syntax-class-properties (https://git.io/vb4yQ) to the 'plugins' section to enable parsing.
  at Object._raise ...
  loc: Position { line: 2, column: 4 },
  pos: 14,
  missingPlugin: [ 'classPrivateProperties', 'classPrivateMethods' ],
  code: 'BABEL_PARSE_ERROR'
}

This works:

babel --plugins @babel/plugin-syntax-class-properties --presets @babel/preset-typescript --extensions '.ts' X.ts

• Extend babel/cli --presets @babel/preset-typescript or @babel/plugin-transform-typescript to only strip the TypeScript declarations and leave the rest as it is, so that adding @babel/plugin-syntax-class-properties is not necessary for the stripping.

@babel-bot
Copy link
Collaborator

Hey @dilyanpalauzov! 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."

@dilyanpalauzov
Copy link
Author

Do I see correctly, that #13232 enables @babel/plugin-syntax-class-properties by default (no-op), so that the typescript-preset can now be used just to strip the type annotations, and it understands this convoluted syntax?

@dilyanpalauzov
Copy link
Author

This is implemented in 7.14.0.

@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 Jul 31, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: question outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants