-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Don't replace (function(){})(); with !function(){}(); unless the return value isn't used #354
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
Comments
Related: estools/esmangle#78 |
I would say adding |
In general I think we prefer the current behaviour, and when you're building for a bookmarklet you can pass |
alexlamsl
added a commit
to alexlamsl/UglifyJS
that referenced
this issue
Mar 1, 2017
Things like Angular Expression and Bookmarklet do not specify `return`, but implicitedly assumes the evaluated value from the final statement to be the return value. fixes mishoo#354 fixes mishoo#543 fixes mishoo#625 fixes mishoo#628 fixes mishoo#640 closes mishoo#1293
alexlamsl
added a commit
to alexlamsl/UglifyJS
that referenced
this issue
Mar 2, 2017
Bookmarklet for instance implicitedly assumes a "completion value" without using `return`. The `expression` option now supports such use cases. Optimisations on IIFEs also enhanced. fixes mishoo#354 fixes mishoo#543 fixes mishoo#625 fixes mishoo#628 fixes mishoo#640 closes mishoo#1293
alexlamsl
added a commit
to alexlamsl/UglifyJS
that referenced
this issue
Mar 3, 2017
Bookmarklet for instance implicitedly assumes a "completion value" without using `return`. The `expression` option now supports such use cases. Optimisations on IIFEs also enhanced. fixes mishoo#354 fixes mishoo#543 fixes mishoo#625 fixes mishoo#628 fixes mishoo#640 closes mishoo#1293
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use UglifyJS to compress and mangle my JS and stick it in a bookmarklet.
This is the bookmarklet's JS (the anon function is to make sure it evaluates to
undefined
):This is the JS after compression (notice the exclamation point):
The exclamation point negates the return value of the anon function so instead of evaluating to
undefined
, it will evaluate totrue
. Then when I prepend thejavascript:
"protocol" the bookmarklet instead navigates to a blank page displayingtrue
.IMO UglifyJS shouldn't negate anonymous functions if the return value is used or in this case if the function is the root function.
The text was updated successfully, but these errors were encountered: