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
Ignore invalid trailing pure annotations #4068
Ignore invalid trailing pure annotations #4068
Conversation
Thank you for your contribution! ❤️You can try out this pull request locally by installing Rollup via npm install kzc/rollup#fix-invalid-trailing-pure-annotations or load it into the REPL: |
Codecov Report
@@ Coverage Diff @@
## master #4068 +/- ##
=======================================
Coverage 97.49% 97.49%
=======================================
Files 193 193
Lines 6818 6824 +6
Branches 2002 2005 +3
=======================================
+ Hits 6647 6653 +6
Misses 84 84
Partials 87 87
Continue to review full report at Codecov.
|
@lukastaegert Can you please take over this PR? I have no idea why
Nor do I understand why coverage would decrease when both code paths of the newly introduced |
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 have no idea why npm audit would fail on only Tests / Node 12 + Extra Tests (Linux) as this PR did not change or introduce any packages
Well, that is the nature of security alerts: They pop up even though you did not change anything just because you triggered the test pipeline. I will see what I can do to fix this on master.
I have no idea why npm audit would fail on only Tests / Node 12 + Extra Tests (Linux) as this PR did not change or introduce any packages
Your changes apparently removed coverage for the case where a Node has more than one annotation.
It seems your code breaks the existing logic to remove trailing annotations if a subsequent node is removed, see my other comment.
console.log('should remain impure'); | ||
console.log('should remain impure'); | ||
|
||
console.log('code'); | ||
console.log('code');/*@__PURE__*///@__PURE__ |
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 looks wrong
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.
Fixed in latest PR by parsing the gap between the pure comment and the call with acorn.parse
instead of just relying on whitespace being there. If it's just whitespace or comments, then there will be zero statements.
Dependencies are now fixed on master |
Ah, okay. I missed that. In addition, a proper fix ought to remove all invalid pure annotations, such as the ones introduced in the additional tests in this PR, as well as cases like the first annotation in the example below:
Notice the invalid pure annotation before a non-call was not emitted by esbuild and uglify. My intention was to also remove such invalid pure annotations, but I was not familiar enough with the comment removal logic. I just put together the original patch to advance the bug fix and don't have the desire to pursue it further. If you could take over this PR, that'd be great. |
As noted in #4062, in some cases invalid annotations trailing a call incorrectly removed the following call which coincidentally would have been tree shaken anyway and the previous tests masked that issue. Further reason to just remove all invalid annotations in the input. |
I didn't plan to refine the patch, but I had an epiphany to use The PR still does not remove invalid pure annotations however. Perhaps this could be done in a future PR. |
Unrelated issue in 2.47.0 discovered when adding more tests: repl
|
that were incorrectly associated with subsequent calls
This PR is good to merge. The unrelated suboptimal tree shaking issue above and removing pure comments not associated with function calls and |
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 like your comprehensive tests! Interesting idea with the acorn parse. My naive approach would have been to use "findFirstOccurrenceOutsideComment", but that one can only search for strings and would not have been able to handle sequence expressions as well with a single call.
Ok, seems GitHub Actions is.. broken? Going to ignore this for now as the previous run was successful. |
https://www.githubstatus.com shows:
|
Ignore invalid trailing pure annotations that were incorrectly associated with subsequent calls.
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
fixes #4062
Description
Ignore invalid trailing pure annotations that were incorrectly associated with subsequent calls causing those calls to be erroneously dropped.
A valid pure annotation comment must precede a call or new expression and only whitespace characters may appear between the annotation comment and the following call.