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 annotation for functions #1883
Comments
I understand why you might want it to work this way, but esbuild's implementation is the way I'm mainly building esbuild to follow existing conventions in the community regarding this stuff. I don't want to have esbuild start inventing new connections that will fragment the community. If there is community momentum around a new convention, then it might make sense to add it to esbuild, but I don't think esbuild is the right tool to be innovating on this kind of thing. Other tools are much more widely used, so it makes sense for these discussions to start with those tools first instead of esbuild in my opinion. |
Ha! I totally understand your point. Seems like we need a standard JS bundling comitee happening soon 👀 In fact, it doesn't sound like a bad idea, doesn't it? L
Anyway, I'll try to gather attention to some people... Authors and maintainers of Webpack, uglifyjs, what else? Rollup?
Get Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: Evan Wallace ***@***.***>
Sent: Thursday, December 23, 2021 11:56:00 PM
To: evanw/esbuild ***@***.***>
Cc: Cristian Pallarés ***@***.***>; Author ***@***.***>
Subject: Re: [evanw/esbuild] Pure annotation for functions (Issue #1883)
I understand why you might want it to work this way, but esbuild's implementation is the way __PURE__ behaves in other tools too, and I think there's value in having this annotation work the same way in all tools instead of having it behave differently depending on the tool. That way people will author packages in a way that works well across tools. There is no formal specification but I believe this convention was originally developed by UglifyJS: mishoo/UglifyJS#1448<mishoo/UglifyJS#1448>. So it should work however they have made it work.
I'm mainly building esbuild to follow existing conventions in the community regarding this stuff. I don't want to have esbuild start inventing new connections that will fragment the community. If there is community momentum around a new convention, then it might make sense to add it to esbuild, but I don't think esbuild is the right tool to be innovating on this kind of thing. Other tools are much more widely used, so it makes sense for these discussions to start with those tools first instead of esbuild in my opinion.
—
Reply to this email directly, view it on GitHub<#1883 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAIHCEFY42L2TIBPJGDUGVTUSOSIBANCNFSM5KVSSMIQ>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
I don't think it needs to be super formal. From what I understand, UglifyJS and Terser are the JS minifiers that are used most often. UglifyJS has 10x more downloads than esbuild for example: https://www.npmtrends.com/esbuild-vs-terser-vs-uglify-js. So you could just start there and see if there's any interest. There may also be an existing discussion about this somewhere since there are surely others who want this feature too. If such a discussion exists, it would also be helpful to read for context. |
I'm going to close this since I'm not planning to work on this. If something like this ships in other more widely-used tools and becomes adopted by the community (i.e. is used in a significant number of popular packages), then we can reopen this issue or create a new one. |
Sadly, I want the same functionality, but I found there are other ways to do it.
|
@bigbanana did you try it? I can't make it work with the latest @evanw I think my case is quite widespread - I'm using https://github.com/colinhacks/zod to build schema validators. Essentially, the library is a bunch of functions which one can use to build module-level constants holding the validators which then can be used on demand. The issue is that without this Right now I have to add an extra transpilation step with a custom babel plugin that just adds these annotations before each call to zod builder. This makes the bundling slow as hell and ultimately defeats the purpose of having super fast build with esbuild. Looking forward to continuing this discussion as it seems the demand is quite high due to how such case is widespread. Essentially, this is a case for any "builder" pattern, whether it's zod, io-ts, injectable-ts, HOF, React HOCs, you name it. It would be extremely handy to have a way to declare function itself as pure. Maybe with annotating function body? function buildString() /* #__PURE__ */ {
// function body
}
// removed by tree-shaking
const fooString = buildString()
// kept by tree-shaking
export const barString = buildString() |
I suspect many have this issue, as you will tend to declare zod schemas upfront at the top of your module, much like you would a typescript type. I'm also generating a lot of my zod code using |
Thanks to this tweet it has come to my attention Google Closure Compiler's @nosideeffects annotation. From their docs:
Much better than the hypotetical "pure" keyword for functions. |
Rollup has support for this with |
Yes. See also #3149, which is already linked above. |
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 returned values are considered pure? Like in the following.
The text was updated successfully, but these errors were encountered: