You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Don't replace (function(){})(); with !function(){}(); unless the return value isn't used #354
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):
(function() {
/*bookmarklet stuff*/
})();
This is the JS after compression (notice the exclamation point):
!function(){/*bookmarklet stuff*/}();
The exclamation point negates the return value of the anon function so instead of evaluating to undefined, it will evaluate to true. Then when I prepend the javascript: "protocol" the bookmarklet instead navigates to a blank page displaying true.
IMO UglifyJS shouldn't negate anonymous functions if the return value is used or in this case if the function is the root function.
In general I think we prefer the current behaviour, and when you're building for a bookmarklet you can pass -c negate-iife=false as @rvanvelzen suggested.
Activity
michaelficarra commentedon Nov 21, 2013
Related: estools/esmangle#78
rvanvelzen commentedon Nov 21, 2013
I would say adding
-c negate_iife=falsewould fix this.mishoo commentedon Nov 21, 2013
In general I think we prefer the current behaviour, and when you're building for a bookmarklet you can pass
-c negate-iife=falseas @rvanvelzen suggested.process code with implicit return statement
process code with implicit return statement
process code with implicit return statement
process code with implicit return statement (#1522)