Skip to content

Writing self-executing functions with !function(){}() is sometimes unsafe #625

@brycecr

Description

@brycecr

Consider the example:

(function(){ doSideEffects(); return 5; })() // A

versus

!function(){ doSideEffects(); return 5; }() // B

A and B cause the same side effects, but the result of each expression is different, 5 in A and false in B

I am uglifying code files that look something like A, which are rewritten to B, and I am running into this issue because the minified files are passed to a processor that uses the result of eval() on the minified code.

I did not find a flag to uglify that controls this behavior, but I was curious whether:

  • Such a flag exists
  • There is a way around this problem without hacking around uglify
  • There should be a flag (or patch) for this
  • Other thoughts of people who understand Uglify better than I do

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