-
-
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
PURE annotations ignored if plugin parses the ast #3979
Comments
Good catch. As we are actually adding this information as non-standard properties to the AST nodes, we should actually be able to do this in |
I started working on it, hope to submit a PR soon |
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
I have submitted a PR, (1) There is a second problem related to the same root cause - the removal of sourceMapping comment is also done only in (2) How can we know the user call to
and in the hooks documentation it says:
But nothing guarantees I have a few possible solutions to this problem, ordered from best to worst IMHO:
|
Yes, separate
We don't, so it should be done in a way that this does not matter. Will try to have a look tomorrow. |
What is the problem if the non-standard fields "pure" and "annotations" are added to other code? |
If we use a well-defined |
Done: #3982 |
* Move pure comment annotation to Graph.contextParse 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 #3979 * Remove unused import * Add test call-marked-pure-with-plugin-parse-ast * Improv test call-marked-pure-with-plugin-parse-ast Use the `onComment` feautre. This expands the coverage. * Change type CommentDescription -> acorn.Comment This change eliminates needless mapping between the types. * Rename annotations in acron.Node 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`. * Remove '_rollupAnnotations' key from Node.keys * Remove dead code Co-authored-by: Yannay Livneh <you@example.com>
Expected Behavior
A plugin which calls
this.parse
(i.e. hookingload
ortransform
) and doesn't modify anything should not affect the tree-shaking.Actual Behavior
If a plugin calls
this.parse
rollup ignores the/*@__PURE__*/
annotation.Root Cause
Accounting for
/*@__PURE__*/
annotation happens in theModule.setSource
function in conjunction with thetryParse
function in the same file. However, this function is not called ifast
already exists.The text was updated successfully, but these errors were encountered: