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
Move pure comment annotation to Graph.contextParse #3981
Move pure comment annotation to Graph.contextParse #3981
Conversation
If a plugin calls `PluginContext.parse` method to parse the AST of the module rollup ignored the `PURE` annotations. This commit fixes the issue by moving the annotation functionality to a central location - the `contextParse` method. Resolves rollup#3979
Codecov Report
@@ Coverage Diff @@
## master #3981 +/- ##
=======================================
Coverage 97.21% 97.22%
=======================================
Files 191 191
Lines 6709 6729 +20
Branches 1962 1969 +7
=======================================
+ Hits 6522 6542 +20
Misses 99 99
Partials 88 88
Continue to review full report at Codecov.
|
Added tests |
Use the `onComment` feautre. This expands the coverage.
Sorry for the delay, things came up. Will look at this soon. |
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.
Thanks a lot! This goes very much in the direction I would have thought. Regarding your comments on the other ticket, though:
- The description of "this.parse" states that it parses code "like Rollup" (and also adds exactly the same plugins), so I like it very much that the users do not need an extra step to add annotations (if they want a "pure" parser, they can always just import their own copy of acorn or whatever other parser). You could see the added annotations as a special "Rollup plugin".
- Annotation properties are non-standard and undocumented—on purpose. Because only that way, we have the freedom to change implementation details. But maybe we should use this chance to change property names. My suggestion would be to prefix the properties with
_rollup
, (i.e._rollupPure
), to make clear:- these are internal implementation details (
_
, official ESTree properties will never have a preceding underscore I presume) - avoid conflicts with other potential tool specific fields
Would you do this in this ticket?
- these are internal implementation details (
src/Graph.ts
Outdated
options.onComment = onCommentOrig; | ||
|
||
markPureCallExpressions(comments.map((cmt) => { | ||
return {...cmt, block: cmt.type == "Block", text: cmt.value}; |
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.
This mapping strikes me as unnecessary if you either push the comments into the array in the previous way or change markPureCallExpressions to work with a slightly changed format?
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 agree. I will change it.
In general I try to keep my changes minimal because it's my first contribution and I don't want to accidentally break anything...
This change eliminates needless mapping between the types.
I am afraid I wasn't clear. I agree that annotations should be added automatically. I just thought it could be convenient if plugins can have a clear API to add more annotations on top of the automatic.
I understand. This is why I suggested a function for this purpose - to keep it separated from the implementation and not touching the nodes directly. Assume a user wishes to skip some nodes in the tree-shaking process, currently there is no way to do it.
Yes, no problem. |
When parsing the JS code we add attributes to acorn.Node for later use: * annotations: acorn.Commnet - the comment that defined the annotation * annotatedPure: boolean - declares this node as pure call/new expression This commit puts all these attributes under one name: `_rollupAnnotations` with a strong type. Thus we clarify that these attributes are for internal use only and decrease the change of ever coliding with internal/future attributes of `acorn.Node`.
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.
Looks good, thanks a lot
If a plugin calls
PluginContext.parse
method to parse the AST of the modulerollup ignored the
PURE
annotations. This commit fixes the issue by movingthe annotation functionality to a central location - the
contextParse
method.Resolves #3979
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Resolve #3979
Description
Move pure comment annotation to Graph.contextParse
If a plugin calls
PluginContext.parse
method to parse the AST of the modulerollup ignored the
PURE
annotations. This commit fixes the issue by movingthe annotation functionality to a central location - the
contextParse
method.