Repository: mishoo/UglifyJS (JavaScript)

Issue:
ufuzz failure
```js
// original code
// (beautified)
var _calls_ = 10, a = 100, b = 10, c = 0;

function f0(a_1, bar, Infinity_2) {
    function f1(bar_1, a) {
        function f2(a_1_2) {
            return;
            var foo = (c = 1 + c, (/[a2][^e]+$/ < null !== ("number" & "function")) * (4 % 5 != (bar_1 && (bar_1.b = /[a2][^e]+$/ % 3))));
        }
        var b = f2([ , 0 ].length === 2, Infinity, a++ + b--);
        function f3() {
            {
            }
            {
                var brake4 = 5;
                do {
                    c = 1 + c, (+"" != void "b") >> (undefined / "foo" == ("bar" != "object"));
                } while ((c = 1 + c, bar = (!2 && (bar_1 &= "number" < 4)) <= (1 ^ 5 ^ NaN % 22)) && --brake4 > 0);
            }
        }
        var b_1 = f3(a++ + (b && b.undefined));
        function f4() {
            {
            }
            try {
                c = 1 + c, (-5 !== 24..toString()) >>> (undefined ^ 5) == ("a", {}) > (c = c + 1, 
                "b");
            } catch (undefined_2) {
            }
        }
        var parseInt = f4("number", !a, []);
        function f5() {
            function f6(foo_1, parseInt, parseInt_1) {
            }
            var foo_2 = f6(1, (c = 1 + c, bar_1 && (bar_1.Infinity = ("b" > 0 | 2 % "b") <= ([ , 0 ][1] << {} | [] << "c"))));
            function f7(a_1_2) {
            }
            var a_2 = f7("c", (c = 1 + c, ("c" + -4) * (parseInt |= -0 ^ 5) & (a_1 && (a_1[bar_1 && typeof bar_1.undefined == "function" && --_calls_ >= 0 && bar_1.undefined((c = 1 + c, 
            ("undefined" ^ "bar" | undefined + "b") - (-3 > -2 != "" > /[a2][^e]+$/)), (c = 1 + c, 
            (23..toString() && 2) < (0 && -3) || Infinity > 24..toString() === (false === -3)))] = ("number" !== "bar") >>> (a_1 && ([ a_1[c = 1 + c, 
            bar && (bar[(c = c + 1) + (void a || 1).toString()[(c = c + 1) + [ (c = 1 + c, ("object" >>> "object") + (-4 & false) > (-3 | 23..toString(), 
            "b" == Infinity)), (c = 1 + c, (-5 ^ 3 | "c" << /[a2][^e]+$/) / (([ , 0 ].length === 2 ^ 4) !== (bar_1 && (bar_1.in >>= -3 >> "c")))), (c = 1 + c, 
            ((a_1 && (a_1[c = 1 + c, 5 / "object" << (this, this) >>> (2 < -2 !== ("c" === 1))] = -3 && "")) ^ (b_1 && (b_1.undefined &= /[a2][^e]+$/ - -3))) < (22 >= Infinity, 
            void "undefined")), (c = 1 + c, ("b" % "foo" <= "b" >>> true) % (([ , 0 ][1] && "undefined") >> (c = c + 1, 
            this))), (c = 1 + c, (5 | [ , 0 ][1]) % (b_1 && (b_1.Infinity = 24..toString() >> 23..toString())) != ((c = c + 1, 
            "object") && + -0)) ]]] += "function" < true != ({} ^ []) !== ([ , 0 ][1] + 0) * ("c" + 0))] ] = [ -4 >>> 3 ]))))));
            function f8(bar, []) {
            }
            var a_2_2 = f8((c = 1 + c, b += ((false << "b") - (c = c + 1, "")) / (([ , 0 ].length === 2) > -4 || "number" ^ "")), "");
        }
        var b = f5(undefined, "undefined", {});
        function f9(NaN_2, async = --b + [ (c = 1 + c, (("number" ^ "function") <= (parseInt = {} >> 3)) >>> ("a" === null) * (-4 << NaN)) ].b) {
            function f10() {
            }
            var a = f10(-5, (c = 1 + c, (5 && "number") - ("undefined" << 1) === ("bar" | NaN) >= "foo" / ([ , 0 ].length === 2)), (c = 1 + c, 
            (c = c + 1, -1) != -0 + "c" == ("number" && "function") <= "number" << Infinity));
            function f11(parseInt, NaN_2_2, bar) {
            }
            var foo_1 = f11(0, -0, (c = 1 + c, 25 >>> 23..toString() >= (b = {} ^ "undefined") != (b_1 && (b_1[--b + {
                Infinity: (c = 1 + c, +(("b" >>> 25) * ("object" !== 4))),
                length: (c = 1 + c, ((24..toString() !== 22) >> (bar_1 && (bar_1[c = 1 + c, ("object" ^ 23..toString()) != 5 <= ([ , 0 ].length === 2) == ("undefined" == "" && [] - NaN)] += "function" - "undefined"))) / (true % ([ , 0 ].length === 2) / (38..toString() == "c"))),
                1.5: (c = 1 + c, (-1 ^ -1) >>> (3 >>> null) >> (b && (b["function" in [ (c = 1 + c, 
                "object" >> -1 << ("undefined" >= 2) === (([ , 0 ][1] && [ , 0 ].length === 2) !== (23..toString(), 
                {}))), (c = 1 + c, b && (b["" in {
                    length: (c = 1 + c, (c = c + 1, 3, "object" || 5) >> ((a = "undefined" <= 3) == "number" * 5)),
                    var: (c = 1 + c, ([] >> true && (-1 && {})) / (("foo" && 3) * (4 + undefined))),
                    foo: (c = 1 + c, [] * 1 >= ("bar" !== Infinity), (4 ^ 4) !== (b && (b[c = 1 + c, 
                    "undefined" / 22 >>> (3 ^ "foo") ^ (NaN - NaN) * ([ , 0 ][1] & 25)] = "b" >>> []))),
                    var: (c = 1 + c, (void /[a2][^e]+$/ < /[a2][^e]+$/ * [ , 0 ][1]) >>> ("undefined" | this, 
                    b += this && -1))
                }] += (+(-4 - {}), b_1 += "c" >> 23..toString() !== "a" + "a"))), (c = 1 + c, (38..toString() >= {}) % (-1 != "undefined") >= (c = c + 1, 
                -1 >> -0)), (c = 1 + c, (Infinity !== -2) <= (3 != -1) && (5 ^ 4, "object" * 4)), (c = 1 + c, 
                (c = c + 1, [] || 22) != "bar" + 3 <= (this == /[a2][^e]+$/)) ]] /= -3 - 1 - ("function" ^ 2)))),
                0: (c = 1 + c, (NaN_2 += this / 5 / (-1 * "bar")) === (c = c + 1, Infinity === true))
            }.var] = (b && (b[c = 1 + c, async && (async[0 === 1 ? a : b] = (true ^ "function", 
            "c" < 24..toString())) || "c" > "c" & (22 || "number")] += 24..toString() === 4)) === -1 > "c"))));
            function f12(Infinity_2, await_1) {
            }
            var b_1 = f12("b", (c = 1 + c, (async += (5 ^ "a") != "foo" * -4) * (parseInt && (parseInt[(c = c + 1) + [ (c = 1 + c, 
            (~24..toString() === (parseInt && (parseInt[c = 1 + c, ("object" > -0) >>> ("" >> 2), 
            undefined !== 24..toString() ^ 22 & 38..toString()] /= "b" ^ {}))) / (4 < [], -0 | 4)) ][c = 1 + c, 
            NaN_2 && (NaN_2.var *= (b += {} ^ 1) << ("bar" ^ 23..toString()) ^ (-5 >= /[a2][^e]+$/) * (-5 === 4))]] = ({} & [ , 0 ].length === 2) == ("function" ^ false)))));
            function f13(bar_1, Infinity_2) {
            }
            var b = f13((c = 1 + c, (-2 !== 2 || /[a2][^e]+$/ >>> [ , 0 ][1]) && ~"function" | -3 >> 3));
            function f14(foo_1) {
            }
            var bar_2 = f14((c = 1 + c, b_1 && (b_1[a++ + typeof (--b + (1 === 1 ? a : b))] = "c" <= "object" <= (3 & this) !== "bar" > "a" < 3 - -5)));
        }
        var Infinity = f9(..."" + bar, "a");
    }
    var await = f1(-1, (c = c + 1) + bar);
    function f15(bar_1, foo) {
        switch (--b + (Infinity in {})) {
          case a++ + (--b + (typeof a_1 == "function" && --_calls_ >= 0 && a_1())):
            c = c + 1;
            switch (a_1) {
              case (c = c + 1) + (-4 / "" >> (NaN || -0) == (({} | -3) !== 1 - true)):
                c = 1 + c, (c = c + 1, "bar") & (5 & [ , 0 ].length === 2) && "c" >= "a" !== [ , 0 ][1] < 38..toString();
                break;

              case 3:
                c = 1 + c, (~"function" && (1 || NaN)) <= (-5 * "c" === -0 <= "");
                break;

              case ((c = 1 + c, ({}, [ , 0 ][1]) >= 23..toString() - 0 ^ (c = c + 1, []) !== (await = "" / "a")) || a || 3).toString():
              case --b + (1 === 1 ? a : b):
                c = 1 + c, ((Infinity_2 && (Infinity_2[c = 1 + c, (delete "a" | 38..toString() - [ , 0 ][1]) / (22 + "foo" === (/[a2][^e]+$/ ^ 1))] = /[a2][^e]+$/ !== 23..toString())) === "b" >= NaN) + ((3 !== 5) << ("number" && 23..toString()));
                break;
            }
            break;

          default:
          case (c = c + 1) + ~b:
            break;

          case b *= a:
            break;
        }
        (c = c + 1) + (await && typeof await.b == "function" && --_calls_ >= 0 && await.b(..."" + Infinity_2, (c = 1 + c, 
        ("a" !== "c" || "c" ^ Infinity) > ((bar_1 = "bar" >= -0) >= -0 / this))));
    }
    var bar = f15(1);
    function f16() {
        {
            var brake16 = 5;
            L54552: do {
                for (var brake17 = 5; bar && brake17 > 0; --brake17) {}
            } while ([] && --brake16 > 0);
        }
        {
            L54553: for (var brake20 = 5; (c = c + 1) + (typeof f4 == "function" && --_calls_ >= 0 && f4((c = 1 + c, 
            0 * "c" === (23..toString() == -5) != (bar = (this == []) + ("number" | 38..toString()))), 4)) && brake20 > 0; --brake20) {
            }
        }
    }
    var foo_1 = f16(24..toString(), --b + (bar = ""));
    function f17(bar_1, b_1) {
        c = c + 1;
        if (typeof bar == "function" && --_calls_ >= 0 && bar(/[a2][^e]+$/)) {} else {
            try {
                {
                    var expr26 = (c = c + 1) + (25 in {
                        a_1: a_1,
                        a: (c = 1 + c, ((-2 && -3) != (4 != 4)) - (2 != true === ([ , 0 ].length === 2) * "foo")),
                        "\t": (c = 1 + c, c = c + 1, NaN - 22 || "a" / /[a2][^e]+$/),
                        undefined: (c = 1 + c, (1 != null ^ 25 === undefined) <= (5 | {}) >>> ([] << 38..toString()))
                    });
                    for (var [ key26 ] in expr26) {
                        try {
                            c = 1 + c, ({} & [ , 0 ][1]) / ("c" === null) ^ [] >>> "c" > (22 > "object");
                        } finally {
                        }
                    }
                }
            } catch (undefined) {
                {
                }
                var b_1_2;
            }
        }
    }
    var a_1 = f17("foo", [ ..."" + Infinity_2, --b + ("number" in {
        "\t": function(bar) {
        },
        0: (c = 1 + c, ((38..toString(), 24..toString()) && false >> NaN) * ((await && (await.foo = 2 - null)) ^ (5 && 1)))
    }), typeof async_1 ][typeof await == "function" && --_calls_ >= 0 && await(typeof a_1_2 !== "string", "undefined", ("undefined" && "") < 23..toString() >> ([ , 0 ].length === 2) == -(false | 4))]);
    function f18(bar_2, undefined_1) {
        {
            var bar_1 = function f19(async, bar_2) {
                c = c + 1;
                if (c = 1 + c, (/[a2][^e]+$/ === NaN, false >>> Infinity) < (undefined >>> 3) % (5 / "bar")) {
                    c = 1 + c, (null ^ -3) >> ("undefined" !== 23..toString()) !== (foo_1 && (foo_1[undefined_1] += (Infinity_2 = "foo" < false) === ("object" !== "a")));
                } else {
                    c = 1 + c, (24..toString() << "object" >> (/[a2][^e]+$/ && undefined)) / ("bar" / "" >>> (38..toString() === "b"));
                }
            }(typeof f1 == "function" && --_calls_ >= 0 && f1("undefined", null, ..."" + a_1), "undefined");
        }
        L54554: for (var brake36 = 5; a++ + function b() {
            {
                var brake37 = 5;
                do {
                    c = 1 + c, (bar_1 >>>= null & this) * +false | void (2 ^ 24..toString());
                } while ((c = 1 + c, ((true, -0) ^ ([] && 22)) >= (("number", -2) ^ 4 != "foo")) && --brake37 > 0);
            }
            {
                var brake39 = 5;
                while ((c = 1 + c, (1 !== -0) >>> ("bar" != 5) ^ (true ^ "foo") >= !"object") && --brake39 > 0) {
                    c = 1 + c, (-3 | 23..toString()) % ("undefined" && "number") / ((4 !== "function") * (1 <= 0));
                }
            }
            {
                return;
                c = 1 + c, ((c = c + 1, [ , 0 ].length === 2) && ("function" && 22)) ^ (undefined_1 = "object" + [ , 0 ][1] >> "foo" + NaN);
            }
        }() && brake36 > 0; --brake36) {}
    }
    var a_1_1 = f18(undefined);
}

var parseInt = f0((~"foo" ^ (parseInt = "b" >= "undefined")) > (3 <= -0 >= (23..toString() ^ 24..toString())), 24..toString(), this);

console.log(null, a, b, c, Infinity, NaN, undefined);
```
```js
// uglified code
// (beautified)
var i, o, n, t, f = 10, a = 100, e = 10, r = 0;

function c(a) {
    var n = function() {
        for (var n = 5; r = 1 + (1 + r), o = !0, 0 < --n; ) {}
    }(e = void e--), e = (function() {
        try {
            r = 1 + r, r += 1;
        } catch (n) {}
    }(), function() {
        r = 1 + r, a && (a.Infinity = !0), r = 1 + r, i && (i[a && "function" == typeof a.undefined && 0 <= --f && a.undefined(0, (r = 1 + (1 + r), 
        "24" < c == 0))] = !0 >>> (i && ([ i[r = 1 + r, o && (o[(r += 1) + "1"[(r += 1) + [ (r = 1 + r, 
        ("b" == c) < 0), (r = 1 + r, -8 / ((2 === [ , 0 ].length ^ 4) !== (a && (a.in >>= -3)))), (r = 1 + r, 
        ((i && (i[r = 1 + r, NaN << this >>> !1] = "")) ^ (n && (n.undefined &= NaN))) < void 0), (r = 1 + r, 
        !1 % (0 >> (r += 1, this))), (r = 1 + r, 5 % (n && (n.Infinity = 0)) != (r += 1, 
        -0)) ]]] += !0)] ] = [ -4 >>> 3 ]))), function([]) {}((r = 1 + r, e += (0 - (r += 1, 
        "")) / (-4 < (2 === [ , 0 ].length) || 0), ""));
    }()), c = function(n, i = --e + [ (r = 1 + r, 1) ].b) {
        var t = (r = 1 + (1 + r), void (r += 1));
        r = 1 + r, f = 0, o && (o[--f + {
            Infinity: 0,
            length: (r = 1 + (1 + r), (!0 >> (a && (a[r = 1 + r, 23 != 5 <= (2 === [ , 0 ].length) == 0] += NaN))) / (!0 % (2 === [ , 0 ].length) / !1)),
            1.5: (r = 1 + r, 0 >> (f && (f["function" in [ !1, (r = 1 + (1 + r), f && (f["" in {
                length: "object" >> (NaN == (t = !1)),
                var: NaN,
                foo: (r = 1 + (1 + ((r = 1 + r) + 1)), 0 !== (f && (f[r = 1 + r, 0] = 0))),
                var: (r = 1 + r, !1 >>> (f += this && -1))
            }] += o += !0)), !0, (-2 !== c) <= !0 && NaN, (r = 1 + (1 + ((r = 1 + r) + 1)), 
            r += 1, [] != "bar3" <= (this == /[a2][^e]+$/)) ]] /= -6))),
            0: (r = 1 + r, (n += this / 5 / NaN) === (r += 1, !0 === c))
        }.var] = !1 === (f && (f[r = 1 + r, i && (i[f] = !1) || 0] += !1)));
        var o = void (i += !0), f = void (r = 1 + (1 + r));
        r = 1 + r, o && (o[t++ + typeof (--f + t)] = !0 <= (3 & this) != 1);
    }(..."" + o, "a");
}

i = !1, o = "24", n = this, t = c(-1, r += 1), o = function() {
    switch (--e + (1 / 0 in {})) {
      case a++ + (--e + ("function" == typeof i && 0 <= --f && i())):
        switch (r += 1, i) {
          case (r += 1) + !1:
            r = 1 + r, r += 1;
            break;

          case 3:
            r = 1 + r;
            break;

          case r = 1 + r, "" + (!1 ^ (r += 1, [] !== (t = NaN)) || a || 3):
          case --e + a:
            r = 1 + r, n && (n[r = 1 + r, 1 / 0] = !0);
        }
        break;

      default:
      case (r += 1) + ~e:
      case e *= a:
    }
    r += 1, t && "function" == typeof t.b && 0 <= --f && t.b(..."" + n, (r = 1 + r, 
    -0 / this <= !1 < !0));
}(), function() {
    var n = 5;
    do {
        for (var i = 5; o && 0 < i; --i) {}
    } while (0 < --n);
    for (var t = 5; (r += 1) + ("function" == typeof f4 && 0 <= --f && f4((r = 1 + r, 
    0 != (o = 38 + (this == []))), 4)) && 0 < t; --t) {}
}((--e, o = "")), i = function() {
    if (r += 1, !("function" == typeof o && 0 <= --f && o(/[a2][^e]+$/))) {
        try {
            var n;
            for ([ n ] in (r += 1) + (25 in {
                a_1: i,
                a: !0 - (!0 === "foo" * (2 === [ , 0 ].length)),
                "\t": NaN,
                undefined: (r = 1 + ((r = 1 + (1 + r)) + 1), !0)
            })) {
                r = 1 + r;
            }
        } catch (n) {}
    }
}((--e, r = 1 + r, t && (t.foo = 2), "function" == typeof t && 0 <= --f && t("string" != typeof a_1_2, "undefined", "" < "23" >> (2 === [ , 0 ].length) == -4))), 
function() {
    0 <= --f && c("undefined", null, ..."" + i), r = 1 + (1 + (r + 1));
    for (var n = 5; a++ + function() {
        for (var n = 5; r = 1 + (1 + r), 0 < --n; ) {}
        for (var i = 5; r = 1 + r, 0 < --i; ) {
            r = 1 + r;
        }
    }() && 0 < n; --n) {}
}(), console.log(null, a, e, r, 1 / 0, NaN, void 0);
```
```
original result:
null 102 806 92 Infinity NaN undefined

uglified result:
null 102 806 84 Infinity NaN undefined
```
```js
// reduced test case (output will differ)

// (beautified)
var parseInt = 0;

parseInt |= 1;

function f9(async = parseInt = 0) {
    console.log(parseInt);
}

f9("a");
// output: 1
// 
// minify: 0
// 
// options: {
//   "compress": {
//     "passes": 1000000,
//     "unsafe": true
//   },
//   "toplevel": true,
//   "output": {
//     "v8": true
//   },
//   "validate": true
// }
```
```
minify(options):
{
  "compress": {
    "passes": 1000000,
    "unsafe": true
  },
  "toplevel": true,
  "output": {
    "v8": true
  }
}

Suspicious compress options:
  evaluate
  passes
  reduce_vars
  unsafe
  unused
```


Discussion:

Patch:
diff --git a/lib/compress.js b/lib/compress.js
index 1dc01f93d3a..e4506f750f7 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -879,6 +879,13 @@ merge(Compressor.prototype, {
             pop(tw);
             return true;
         });
+        def(AST_DefaultValue, function(tw) {
+            this.name.walk(tw);
+            push(tw);
+            this.value.walk(tw);
+            pop(tw);
+            return true;
+        });
         def(AST_Defun, reduce_defun);
         def(AST_Do, function(tw) {
             var saved_loop = tw.in_loop;


Test patch:
diff --git a/test/compress/default-values.js b/test/compress/default-values.js
index bda32c1bdb1..eefa6e0e748 100644
--- a/test/compress/default-values.js
+++ b/test/compress/default-values.js
@@ -1076,3 +1076,27 @@ issue_4446_2: {
     expect_stdout: "PASS 42"
     node_version: ">=6"
 }
+
+issue_4458: {
+    options = {
+        evaluate: true,
+        reduce_vars: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        var a = "PASS";
+        function f(b = a = "FAIL") {
+            console.log(a, b);
+        }
+        f(42);
+    }
+    expect: {
+        var a = "PASS";
+        (function(b = a = "FAIL") {
+            console.log(a, b);
+        })(42);
+    }
+    expect_stdout: "PASS 42"
+    node_version: ">=6"
+}