mishoo/UglifyJS

default `negate-iife=false` please

tomByrer opened this issue · 8 comments

Not sure why you'd want to alter code behavior the author added in the first place?
ref: #354

Program completion value is almost never used. esmangle also defaults to not preserving program completion value. 👎.

aside: Is there an option to preserve program completion value in uglifyjs?

Closure keeps IIFEs as-is. Most of the code I compress is not mine, & there either no tests or I don't have time to install & run them. I think many others are in the same situation.

My use case is compressing files before I host them on jsDelivr free CDN. So I prefer to keep code close as authors published it, just smaller.

Program completion value is almost never used.

That may be true. So @michaelficarra if you'd like to make & test a PR everytime I find a program completion in the wild, I can ping you! But I suspect you are good at keeping yourself busy also ;)

@michaelficarra there is, -c negate_iife=false.

To be honest, this transformation doesn't bring much to the table. The size savings are probably negligible, we could make it off by default.

However, @tomByrer — why don't you simply pass negate_iife=false in your build scripts?

@mishoo that's nowhere near sufficient for completion value preservation. Not every program is wrapped in an IIFE.

@mishoo I don't use build scripts for alot of my compression. I often use online UglifyJS before uploading to the CDN for those rare projects that don't provide minified version. Perhaps I could just fork it & hardcode the flag myself, but I see others don't like that surprise either.

Not every program is wrapped in an IIFE.

Very true! I think I have to deal with more IIFE usage than you. Since jsDelivr only hosts front-end code (1/3 are of the ~1200 projects we host are jQuery plugins), I'll see alot more IIFEs than a CoffeeScript guru like you! 😀
A few even lead with a ; & their concern is well-founded since we do sever-side concocting.

But preserving completion value is not just about IIFEs. It's about not changing the completion value of the final statement in the program.

@michaelficarra Indeed. Then nope, we don't have an option for it. Other than negating IIFE-s, the one thing that could affect final value is discarding constant side-effect-free ExpressionStatement-s. I could add an option for it if there's sufficient interest (I personally don't see the point though).

Edit: s/constant/side-effect-free/

Closing in favor of #640.