Support for static class properties without babel plugin
See original GitHub issue🚀 Feature Proposal
A babel plugin shouldn’t be required to use static class properties (a native Node LTS feature now).
Motivation
Node LTS is v12.x now which supports static class properties. Developers ideally shouldn’t need to include a babel plugin for a natively supported feature 🙏
UPDATE: I was able to work around this without a babel plugin by specifying transform: {}
in jest.config.js. This is still not ideal, however. I would expect jest to work out of the box for natively-supported code.
Example
This error wouldn’t happen when I run my tests.
SyntaxError: /Users/david/repos/mission-control-api/classes/BaseModel.class.js: Support for the experimental syntax 'classProperties' isn't currently enabled (26:3):
24 | ...super.schema,
25 | */
> 26 | static schema = {
| ^
27 | createdAt: { type: Date, required: true },
28 | id: { type: CosmosId },
29 | updatedAt: { type: Date, required: true },
Add @babel/plugin-proposal-class-properties (https://git.io/vb4SL) to the 'plugins' section of your Babel config to enable transformation.
at Parser.raise (node_modules/@babel/parser/lib/index.js:6930:17)
at Parser.expectPlugin (node_modules/@babel/parser/lib/index.js:8328:18)
at Parser.parseClassProperty (node_modules/@babel/parser/lib/index.js:11617:12)
at Parser.pushClassProperty (node_modules/@babel/parser/lib/index.js:11582:30)
at Parser.parseClassMemberWithIsStatic (node_modules/@babel/parser/lib/index.js:11556:14)
at Parser.parseClassMember (node_modules/@babel/parser/lib/index.js:11453:10)
at node_modules/@babel/parser/lib/index.js:11408:14
at Parser.withTopicForbiddingContext (node_modules/@babel/parser/lib/index.js:10486:14)
at Parser.parseClassBody (node_modules/@babel/parser/lib/index.js:11385:10)
at Parser.parseClass (node_modules/@babel/parser/lib/index.js:11359:22)
Pitch
Why does this feature belong in the Jest core platform?
I believe it would be best if jest can run on valid, native NodeJS code with no other dependencies or additional configuration 😃
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:6
Top Results From Across the Web
babel/plugin-proposal-class-static-block
A class with a static block will be transformed into a static private property, whose initializer is the static block wrapped in an...
Read more >babel/plugin-proposal-class-properties not being picked up ...
I am trying to incorporate React Native Calendars into my React webapp. I have run npm install --save react-native-calendars.
Read more >Babel 7.14 enables class fields & private methods by default ...
This plugin transforms class properties in such a way that we can define class properties using property initializer syntax (i.e., by using the ......
Read more >babel-plugin-transform-class-properties - npm package - Snyk
This plugin transforms static class properties as well as properties declared with the property initializer syntax For more information about how to use ......
Read more >7.14.0 Released: New class features enabled by default ...
We added support for Stage 1 async do expressions (using ... Thus, you can remove @babel/plugin-proposal-class-properties and ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is Babel’s decision but I would expect that it will be enabled by default once it is stage 4.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.