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
Extending the pure annotation for functions #5234
Comments
That's what $ cat test.js
function addTwo(number) {
return number + 2;
}
// Will be removed
addTwo(4);
// Will be removed
const x = addTwo(3);
// This will be kept
export const y = addTwo(2); $ uglify-js test.js --compress toplevel,pure_funcs=addTwo --beautify
function addTwo(number) {
return number + 2;
}
var y = addTwo(2);
export {
y
}; |
Thanks for suggesting Why I think reading a function annotation would be good:
Now, I have no idea how hard would be to implement this annotation into UglifyJS, but it seems it shouldn't be a huge deal if it already produces an AST? What do you think? |
@alexlamsl mentioning you just in case you didn't see the notification |
Hey there, Uglify team! 👋 Please consider adding support for granular function purity (via Rollup's lead maintainer: rollup/rollup#2960 (comment)
Esbuild's creator: evanw/esbuild#1883 (comment)
Fábio, a maintainer of Terser, also expressed interest in this extension of |
I made an other issue for this feature with a more detailed breakdown of motivation and benefits #5614. |
Google Closure has a better solution for this problem than a pure annotation for functions. They do have a
|
Currently, the
/* @__PURE__ */
annotation must be used individually on every returned value for a given call.Could it be possible to allow using the annotation on a function, so all its executions and returned values are considered pure? Like in the following.
I started the same discussion on the esbuild repository, which leaded me here since @evanw prefers not to do any takes unless they are a standarised feature.
The text was updated successfully, but these errors were encountered: