Skip to content
This repository was archived by the owner on Dec 5, 2019. It is now read-only.
This repository was archived by the owner on Dec 5, 2019. It is now read-only.

Inline function optimization fails to define some arguments #265

@jamesopti

Description

@jamesopti

This issue appears to be similar/related to #264 but without any variable name clashing, which I think would make it more likely to come across and thus I'm reporting it as a separate issue.
(also filed issue #3012 with Uglify-es)

When only a single occurrence of a method happens, Uglify-es is attempting to inline the only usage of the function, but is failing to declare the second variable, causing an uncaught exception.

Using:
Webpack @4.1.1
Uglifyjs-webpack-plugin @1.2.4

Minimally reproducible main.js:

(function(mod) {
  mod();
})(function() {
  function getMaxSeverity(ax, bx) {
    if (ax === "error") {
      return ax;
    } else {
      return bx;
    }
  }
  function main() {
    var arr = ['test'];
    for (var i = 0; i < arr.length; i++) {
      console.log(getMaxSeverity('one', 'two'));
    }
  }
  main();
});

Minifies to:

function(o, n) {
    !function() {
        !function() {
            for (var o = ["hey"], n = 0; n < o.length; n++)
                console.log("error" === (e = "one") ? e : bx);
            var e
        }()
    }()
}

Expected
two

Actual
Uncaught exception bx is not defined

More reproducible test cases here showing working versions of inlining:
https://github.com/jamesopti/uglifyjs-webpack-issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions