-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Rollup class fields support #3488
Conversation
package.json
Outdated
}, | ||
"dependencies": { | ||
"acorn-class-fields": "github:guybedford/acorn-class-fields#acorn-update", | ||
"acorn-static-class-features": "github:guybedford/acorn-static-class-features#patch-1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be devDependencies
of course.
Thank you for your contribution! ❤️You can try out this pull request locally by installing Rollup via
or load it into the REPL: |
6c5970e
to
7c264cd
Compare
Codecov Report
@@ Coverage Diff @@
## master #3488 +/- ##
==========================================
+ Coverage 95.96% 96.06% +0.10%
==========================================
Files 174 175 +1
Lines 5947 5950 +3
Branches 1752 1752
==========================================
+ Hits 5707 5716 +9
+ Misses 123 118 -5
+ Partials 117 116 -1
Continue to review full report at Codecov.
|
7c264cd
to
d5d5504
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed the dependencies and also added a simple test. Was also able to solve an old issue related to this now that we can test this: #2775. From my side this is ready to be merged.
I just hope they can agree on an AST structure for optional chaining and nullish coalescing soon so that we can complete ES2020 support soon...
On second thought, maybe I want to at least add the new AST node types for class properties... |
Ok, Nodes are added. |
I do not pretend to understand this magic, but it looks great! I suppose we can remove the WIP status of this PR then? Should we test static expressions and static functions as well here? |
*private static methods I mean |
Definitely
Please feel free to add this, I must admit I was not entirely sure what was included. I will not be able to look at this again before tonight. |
@guybedford I extended the test to include all new features and, who would have thought, support is incomplete: Private methods, setters and getters produce an "unexpected token" while parsing. I assume this needs to be fixed in the plugin. Should we still release it as "incomplete support"? It still provides some value and also fixes a bug. |
You can remove the comments in my test case to see what I mean. |
@lukastaegert thankfully, for now at least, I believe this syntax support level exactly matches Chrome stable (and hence the major usage). But yes as soon as Chrome lands those that will be an issue. Perhaps maintaining and developing the forks as part of Rollup will be an option here. Note that also eg Terser doesn't support any of this yet (I know @fabiosantoscode was originally against it)... perhaps this is another area where RollupJS could assist with funding for these features. |
70741c7
to
86843d1
Compare
You are right, Chrome does not support any of the missing ones. It also does not support static private methods, so there is at least one additional case that is supported. Then I will push this one out as well. |
Private methods and accessors, both static and instance, are implemented in V8 and are unflagged now in Chrome 84 as well. Will Rollup be supporting these as well, and if so, should an issue be opened to track that? |
I doubt it’s really this simple, but FWIW, in this code — // Parse private static methods
parsePropertyName(prop) {
if (prop.static && this.type == this.privateNameToken) {
this.parsePrivateClassElementName(prop);
} else {
super.parsePropertyName(prop);
}
} If I remove |
You can create an issue, but this is not Rollup code, without an upstream issue in the corresponding acorn plugin (likely https://github.com/acornjs/acorn-private-class-elements), nothing will move forward here. |
Cool — in that case, it seems like maybe Rollup support (at least for instance methods) might end up being “free” if the upstream plugin is updated to handle these cases. Will investigate a bit further, thanks. |
Yes, that is my expectation. Others will profit from this as well. |
Hey there! I was against class fields, but I wouldn't stop progress for just that :) they are implemented in Terser. I don't recall if I got to implementing private fields too, though. |
This adds class fields and static class fields support.
The reason being that it is almost impossible to add via the inject mechanism due to the different Acorn instances in play giving this error - https://github.com/acornjs/acorn-private-class-elements/blob/master/index.js#L23.
In addition both plugins needed to be forked to add the Acorn 7 support which is missing (with other similar PRs outstanding for some time).
For me personally this was to get the feature working, but I suspect there may be components of the treeshaking that will need attention. In addition the tests have not been fleshed out, hence the WIP status. But this is functional in my own test cases.
Maybe RollupJS can distribute some of its funds to help Acorn plugin development. @adrianheine would financial support help here in moving things forward?
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description