Skip to content

Don't replace (function(){})(); with !function(){}(); unless the return value isn't used #354

@Daniel-Hug

Description

@Daniel-Hug

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions