-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Proposal for marking functions as pure #1293
Comments
Well, those aren't reassuring. A lot of discussion/bike-shedding and no merged PRs. Maybe Rollup could lead the effort here since it's focus is specifically on tree-shaking? |
@nathancahill Well, it isn't as big of a deal in Rollup because Rollup's dead-code elimination is already really good. Notice that it was able to completely remove the unused class and I like the idea of a comment hint, but I personally think it would be better to wait for it to be standardized in UglifyJS before adding it to Rollup, so that way both projects can share the same comment annotation. Even if it was added to Rollup first, I don't think that would encourage UglifyJS to add it. But I'm not a part of the Rollup team, maybe they feel differently from me. |
Looks like Uglify has stabilized on using |
This would be useful for D3.js. Related discussion there: d3/d3#3076 |
Please keep Tree Skaking automatic and help keep codebases clean. Thank you. |
I'm attempting to write the diff for supporting uglify-style comments. Tracking my progress in #2423. |
UPDATED PROPOSAL
UglifyJS2, as of 2.8.0, now supports marking pure with this comment:
/*#__PURE__*/
I propose that Rollup adopt similar behavior to help with tree-shaking.
PREVIOUS PROPOSAL (before UglifyJS release)
I'm proposing adding eslint-style comment annotations to give users more control over tree-shaking:
tree-shaking: pure
"Affected expressions will not mark their nodes for inclusion"tree-shaking: auto
"Current behavior"tree-shaking: side-effects
"Affected expressions mark their nodes for inclusion"Overriding expression marks on a single line:
Overriding expression marks in a block, reverting to auto at the end of the block:
Overriding marks for all expressions in a file:
/* rollup-tree-shaking pure */
Marking a line as having side-effects. This expression is marked for inclusion:
Pros
Cons
pure
annotation should beunsafe-pure
to make the risk clear.The text was updated successfully, but these errors were encountered: