Repository: mishoo/UglifyJS (language: javascript)

Issue:
ufuzz failure
```js
// original code
// (beautified)
var _calls_ = 10, a = 100, b = 10, c = 0;

switch (--b + (b = a)) {
  case await (a++ + -2 || a || 3).toString():
    {
        var arguments_1 = function async_2() {}();
    }
    break;

  default:
    {
        var b_1 = function f0() {
            {
                var brake4 = 5;
                while ((c = c + 1) + a++ && --brake4 > 0) {
                    return;
                    typeof arguments_1 == "function" && --_calls_ >= 0 && arguments_1([]);
                }
            }
        }();
    }
    {
        var expr6 = [ [ a++ + a++ ] ].NaN;
        L23126: for (var key6 in expr6) {
            c = 1 + c;
            var foo = expr6[key6];
            {
                var brake7 = 5;
                L23127: do {
                    {
                        var NaN_2 = function f1(key6_1, a_1, b) {
                            function f2(b, foo) {
                                function f3(yield_1, b_1 = true, key6) {
                                }
                                var b_1 = f3((c = 1 + c, c = c + 1, "function" / "foo" - (c = c + 1, 
                                38..toString())), (c = 1 + c, ([ , 0 ][1] < 2) >>> (c = c + 1, 
                                "c") != (foo = (NaN | 4) != 0 >>> 24..toString())));
                                function f4(foo_1, await_2, yield_2) {
                                }
                                var key6_2 = f4(-5);
                            }
                            var b = f2();
                            function f5(foo_1, b, let_2) {}
                            var b_2 = f5(-5, a++ + ((Infinity << ([ , 0 ].length === 2) ?? -1 === 23..toString()) !== (25 * "function" && 22 !== -5)));
                            function f6() {
                                switch (c = 1 + c, (([ , 0 ].length === 2 | null) & "undefined" > 24..toString()) % ((4, 
                                -0) || /[a2][^e]+$/ >>> -4)) {
                                  default:
                                    ;

                                  case c = 1 + c, (false <= 24..toString() !== (38..toString() ^ -5)) - (([ , 0 ].length === 2 !== 5) > (this || 0)):
                                    ;
                                    break;

                                  case c = 1 + c, (Object.isExtensible(b) && (b.a >>= (-2 - Infinity) * (undefined & 25))) < (-0 && 2) >> (undefined > Infinity):
                                    ;

                                  case c = 1 + c, "a" / 4 * (true >> ([ , 0 ].length === 2)) << (4 <= ([ , 0 ].length === 2) ^ (key6 &= 23..toString() + 5)):
                                    ;
                                    break;
                                }
                                {
                                    return c = 1 + c, [ , 0 ][1] <= true >= (-3 && 23..toString()) === ((5 & false) != (22 ^ "c"));
                                }
                                for (var brake11 = 5; (c = 1 + c, ("function" | 23..toString()) ** (Object.isExtensible(key6) && (key6[c = 1 + c, 
                                (!-3 == "undefined" * NaN) < (undefined === this | 38..toString() != ([ , 0 ].length === 2))] = "bar" * Infinity)), 
                                b = (4 ^ undefined, c = c + 1, "object")) && brake11 > 0; --brake11) {
                                    c = 1 + c, ("undefined" ^ [ 3n ][0] > 2) - (23..toString() + this) === ((Object.isExtensible(key6) && (key6[c = 1 + c, 
                                    (0 !== "function" === "object" >> "function") % (({} == "c") % (25 | undefined))] += false ^ false)) | !([ 3n ][0] > 2));
                                }
                            }
                            var a_2 = f6(~b, --b + (arguments_1 && typeof arguments_1.in == "function" && --_calls_ >= 0 && arguments_1.in(false)));
                        }(a++ + (b = a));
                    }
                } while (a++ + (("b" || -1) << null % 1 == (({} || "object") != (undefined & -4))) && --brake7 > 0);
            }
        }
    }

  case ++b:
    {
        var brake13 = 5;
        while (function() {
            switch ({}[--b + {
                null: --b + {
                    Infinity: (c = 1 + c, (23..toString() <= -3) >> ~25 <= (b_1 += (-4 + "number") * +"undefined"))
                }.static,
                Infinity: arguments_1 = a++ + (c = 1 + c, (Object.isExtensible(arguments_1) && (arguments_1[c = 1 + c, 
                Object.isExtensible(b_1) && ({
                    static: b_1[a--]
                } = {
                    static: void [] == 2 - 38..toString() | (25 && -4) <= [] / "c"
                })] += 0 ^ 4)) >= -3 - /[a2][^e]+$/, c = c + 1, "undefined", -2 < "")
            }[!function() {
                {
                    var brake15 = 5;
                    while ((c = 1 + c, (-5 && 2, 5 == 38..toString()) < 4 % 25 >> (NaN || undefined)) && --brake15 > 0) {
                        c = 1 + c, ("bar" ?? "foo") == [ , 0 ][1] < true | ("undefined" | null && (c = c + 1, 
                        24..toString()));
                    }
                }
                {
                    var brake17 = 5;
                    do {
                        c = 1 + c, ({} != "object" ?? 23..toString() & this) ^ (4 >>> undefined) - (5 >= null);
                    } while ((c = 1 + c, (23..toString() ?? 38..toString()) + ("number" === Infinity) <= (3 > undefined) >>> (this & "bar")) && --brake17 > 0);
                }
                {
                    var expr19 = (c = 1 + c, ("c" ^ "object", Infinity < 2) % ((Object.isExtensible(b_1) && (b_1.static = "object" !== "bar")) & (22 | -3)));
                    for (var key19 in expr19) {
                        c = 1 + c, (([ , 0 ].length === 2 ^ Infinity) == (24..toString() || "object")) << (5 / 38..toString() ?? 24..toString() % -1);
                    }
                }
                {
                    var brake21 = 5;
                    do {
                        c = 1 + c, (b_1 = (c = c + 1, "") % (-4 | "function")) >>> ((-2 != -3) >> 25 / "object");
                    } while ((c = 1 + c, (-1 >>> {} << (0 <= /[a2][^e]+$/)) / ("a" & this | (5 || -2))) && --brake21 > 0);
                }
            }()]]) {
              case --b + [ a++ + b--, a++ + arguments_1 ]:
                {
                    var brake23 = 5;
                    do {
                        if ((c = c + 1) + (b += a)) {
                            for (var brake25 = 5; ("b" ^ 1 || (-5, "")) !== (5 < {}) * +22 && brake25 > 0; --brake25) {
                                var brake26 = 5;
                                do {
                                    c = 1 + c, -4 * [] === (Object.isExtensible(arguments_1) && (arguments_1[c = 1 + c, 
                                    c = c + 1, ("" >>> 4) % (undefined > /[a2][^e]+$/)] = -3 || "b")) & "number" + 0 + (Object.isExtensible(b_1) && (b_1.NaN &&= -1 % "c"));
                                } while ((c = 1 + c, Object.isExtensible(arguments_1) && (arguments_1[[ (c = 1 + c, 
                                ("function" >> NaN | (null && 38..toString())) >> (-1 - 3 == 2 - -2)) ][c = 1 + c, 
                                (({} == false) >= ~-5) >> (void -5 === void -4)]] = (38..toString() && Infinity) & (Object.isExtensible(arguments_1) && (arguments_1[c = 1 + c, 
                                (Object.isExtensible(arguments_1) && (arguments_1.async = (0 + "bar") % (1 >>> 25))) & (NaN ^ -2 ^ ("a" | "function"))] = "b" - ""))), 
                                ("b", Infinity) - -5 / "number") && --brake26 > 0);
                            }
                        } else {
                            var expr28 = typeof (c = 1 + c, ~([ , 0 ][1] === /[a2][^e]+$/) << ((Object.isExtensible(b_1) && (b_1[c = 1 + c, 
                            25 + "c" >= 25 / {} <= ("b" != 0 == ("number" & null))] = 1 == "function")) << ("" ^ "undefined")));
                            for (var key28 in expr28) {
                                c = 1 + c;
                                var b_1 = expr28[key28];
                                var let_1 = (c = 1 + c, Object.isExtensible(b_1) && (b_1[a++ + typeof (c = 1 + c, 
                                (-4 === [ , 0 ][1] && -3 ^ []) * ((-2 ^ NaN) * (0 * ([ , 0 ].length === 2))))] = (([ , 0 ].length === 2) << "undefined") % (/[a2][^e]+$/ / "foo")) && (0 > ([ , 0 ].length === 2)) << (Object.isExtensible(let_1) && (let_1.next = -2 - 25)));
                            }
                        }
                    } while (--b + (+(!("b" > -0) << (4 / 2, false - "function")) || a || 3).toString() && --brake23 > 0);
                }
                break;

              default:
                var arguments_1 = 1 === 1 ? a : b;

              case (c = c + 1) + (typeof arguments_1 == "function" && --_calls_ >= 0 && arguments_1((c = c + 1) + (arguments_1 && arguments_1[b = a]), (c = c + 1) + (b = a))):
                ;
                {
                    var arguments_1 = function a_2() {
                        {
                            return;
                            c = 1 + c, ({} !== undefined || (c = c + 1, "function")) >= (Object.isExtensible(b_1) && (b_1[--b + (-1 in [ (c = 1 + c, 
                            (Infinity % -0 && -4 > 38..toString()) >> ((arguments_1 &&= -5 % -3) > ("bar" > 23..toString()))), (c = 1 + c, 
                            (false ^ 0, "number" - "number") << (-0 * 0 >> (b_1 = "foo" + -2))) ])] = "object" * "a" <= (-2 || [ , 0 ][1])));
                        }
                    }(2, -2, (c = c + 1) + (arguments_1 = --b));
                }
                try {
                    {
                        var brake35 = 5;
                        do {
                            (c = c + 1) + ({} in {
                                "\t": (c = 1 + c, (arguments_1 <<= (Infinity & "bar") / (22 >> 4)) >> (Infinity ^ 25) % (25 + Infinity)),
                                then: (c = 1 + c, (c = c + 1, ([ , 0 ].length === 2) * 25) >= (4 == "b") / (c = c + 1, 
                                23..toString()))
                            });
                        } while ("foo" && --brake35 > 0);
                    }
                } catch (a_2) {
                    (c = c + 1) + /[abc4]/g.exec(((c = 1 + c, ("c" * [ , 0 ][1] >= (38..toString() & "object")) / (Object.isExtensible(a_2) && (a_2[/[abc4]/g.exec(((c = 1 + c, 
                    (Object.isExtensible(arguments_1) && (arguments_1[c = 1 + c, 
                    ([ , 0 ][1] >> -3 >> "bar" + undefined) - ((Object.isExtensible(arguments_1) && (arguments_1.foo %= {} && -0)) === (-0 & -0))] &&= "a" >> {})) ^ (1 ^ false) ^ NaN / [] << (Object.isExtensible(arguments_1) && ({
                        set: arguments_1[c = 1 + c, (c = c + 1, 2 / -4) >>> (Object.isExtensible(arguments_1) && (arguments_1.then += - -4 >= (22 & -2)))]
                    } = {
                        set: "b" - 1
                    }))) || b || 5).toString())] **= (24..toString() - -4) % (c = c + 1, 
                    "object")))) || b || 5).toString());
                    L23128: {
                        c = 1 + c, "foo" / 0 >> -2 + -3 > ((this, "b") === [ , 0 ][1] > "bar");
                    }
                }
                break;

              case b = a:
                --b + {
                    foo: a++ + (c = c + 1, void -5) * ((-5 ?? -2) & (c = c + 1, 
                    [ , 0 ][1]))
                };
                break;
            }
        }() && --brake13 > 0) {
            c = c + 1;
        }
    }
    for (var brake43 = 5; (c = c + 1) + (a++ + (b_1 && b_1[a++ + (b_1 && typeof b_1.foo == "function" && --_calls_ >= 0 && b_1.foo(typeof b_1 == "function" && --_calls_ >= 0 && b_1((c = c + 1) + !(!(23..toString() + Infinity) >>> (24..toString() >= "") - (3 != 23..toString())))))])) && brake43 > 0; --brake43) {
        if (arguments_1 && arguments_1[--b + (1 === 1 ? a : b)]) {
            L23129: for (var brake46 = 5; a++ + (b_1 && typeof b_1.Infinity == "function" && --_calls_ >= 0 && b_1.Infinity([ (c = 1 + c, 
            (Object.isExtensible(b_1) && (b_1.in = "function" === {} != 0 < 24..toString())) ^ [ , 0 ][1] / "undefined" > (Infinity !== "c")), (c = 1 + c, 
            (1 && NaN) !== (1 || Infinity) != ("a" > -0 | {} / 5)), (c = 1 + c, 
            c = c + 1, arguments_1 -= ({} || "") < (2 < 24..toString())) ])) && brake46 > 0; --brake46) {
                b >>>= a;
            }
        }
        a++ + (1 === 1 ? a : b);
    }
    break;

  case a++ + !((5 % "" >> void "function") + (-4 << 0 ^ (Object.isExtensible(b_1) && ({
        [(c = 1 + c, (false >= {} ^ (NaN ^ null)) > ({} ^ 3) / (22 - -5))]: b_1.null
    } = {
        foo: 2 ^ [ , 0 ].length === 2
    })))):
    var arguments_1_1;
    break;
}

L23130: for (var brake50 = 5; "b" && brake50 > 0; --brake50) {
    var brake51 = 5;
    while (typeof f8 == "function" && --_calls_ >= 0 && f8("b") && --brake51 > 0) {
        c = c + 1;
    }
}

console.log(null, a, b, c, Infinity, NaN, undefined);
```
```js
// uglified code
// (beautified)
var n = 10, i = 100, t = 10, a = 0;

switch (--t + (t = i)) {
  case await (i++ - 2 || i || 3).toString():
    var e = void 0;
    break;

  default:
    a += 1;
    var o, f = void i++, r = [ [ i++ + i++ ] ].NaN;
    for (o in r) {
        var a = 1 + a, s = (r[o], 5);
        do {
            (t => {
                a = (a = 1 + a) + 1 + 1, 38..toString(), a = 1 + a, a += 1, NaN, 
                t = void 24..toString(), i++, Infinity << (2 === [ , 0 ].length) ?? 23..toString(), 
                function() {
                    switch (a = 1 + a, ((2 === [ , 0 ].length | null) & 24..toString() < "undefined") % 0) {
                      default:
                      case a = 1 + a, (!1 <= 24..toString() !== (-5 ^ 38..toString())) - ((this || 0) < (2 === [ , 0 ].length !== 5)):
                        break;

                      case a = 1 + a, (Object.isExtensible(t) && (t.a >>= (-2 - Infinity) * (25 & undefined))) < -0 >> (undefined > Infinity):
                      case a = 1 + a, NaN * (!0 >> (2 === [ , 0 ].length)) << (4 <= (2 === [ , 0 ].length) ^ (o &= 23..toString() + 5)):
                    }
                    a = 1 + a, 23..toString();
                }((--t, e && "function" == typeof e["in"] && 0 <= --n && e["in"](!1)));
            })(void (t = ++i));
        } while (i++ + (0 == ({} != (-4 & undefined))) && 0 < --s);
    }

  case ++t:
    switch (aa = y = S = d = u = g = N = l = b = c = void 0, {}[--t + {
        null: --t + {
            Infinity: (a = 1 + a, (23..toString() <= -3) >> -26 <= (u += NaN))
        }["static"],
        Infinity: S = i++ + (a = 1 + a, Object.isExtensible(S) && (S[a = 1 + a, 
        Object.isExtensible(u) && ({
            static: u[i--]
        } = {
            static: null == 2 - 38..toString() | -4 <= [] / "c"
        })] += 4), a += 1, !0)
    }[!function() {
        for (var t = 5; a = 1 + a, (5 == 38..toString()) < 4 >> (NaN || undefined) && 0 < --t; ) {
            a = 1 + a;
        }
        for (var n, i = 5; a = 1 + a, "object" != {} ?? 23..toString(), undefined, 
        a = 1 + a, (23..toString() ?? 38..toString()) + ("number" === Infinity) <= (undefined < 3) >>> ("bar" & this) && 0 < --i; ) {}
        for (n in a = 1 + a, (Infinity < 2) % (-1 & (Object.isExtensible(u) && (u["static"] = !0)))) {
            a = 1 + a, Infinity, 24..toString(), 5 / 38..toString() ?? 24..toString();
        }
        for (var e = 5; a = 1 + a, u = 0, a = 1 + (a += 1), (-1 >>> {} << !1) / ("a" & this | 5) && 0 < --e; ) {}
    }()]]) {
      case --t + [ i++ + t--, i++ + S ]:
        var c = 5;
        do {
            if ((a += 1) + (t += i)) {
                for (var b = 5; 1 != 22 * (5 < {}) && 0 < b; --b) {
                    for (var l = 5; a = 1 + a, Object.isExtensible(S) && (S[a = 1 + a, 
                    a += 1, 0 % (undefined > /[a2][^e]+$/)] = -3), Object.isExtensible(u) && (u.NaN &&= NaN), 
                    a = 1 + a, Object.isExtensible(S) && (S[[ (a = 1 + a, ("function" >> NaN | null) >> !1) ][a = 1 + a, 
                    (4 <= (0 == {})) >> !0]] = (38..toString() && Infinity) & (Object.isExtensible(S) && (S[a = 1 + a, 
                    (Object.isExtensible(S) && (S["async"] = NaN)) & (-2 ^ NaN ^ 0)] = NaN))), 
                    Infinity - NaN && 0 < --l; ) {}
                }
            } else {
                a = 1 + a;
                var g, N = typeof (-1 << ((Object.isExtensible(u) && (u[a = 1 + a, 
                25 / {} <= "25c" <= !1] = !1)) << 0));
                for (g in N) {
                    a = 1 + a;
                    var u = N[g], d = (a = 1 + a, Object.isExtensible(u) && (u[i++ + (a = 1 + a, 
                    typeof ((-2 ^ NaN) * (0 * (2 === [ , 0 ].length)) * !1))] = ((2 === [ , 0 ].length) << "undefined") % NaN) && ((2 === [ , 0 ].length) < 0) << (Object.isExtensible(d) && (d.next = -27)));
                }
            }
        } while (--t + 1..toString() && 0 < --c);
        break;

      default:
        var S = i;

      case (a += 1) + ("function" == typeof S && 0 <= --n && S((a += 1) + (S && S[t = i]), (a += 1) + (t = i))):
        S = function aa() {}((a += 1, S = --t));
        try {
            for (var y = 5; a = 1 + (a += 1), S <<= "bar" & Infinity, Infinity, 
            Infinity, a = 1 + a + 1 + 1, 23..toString(), 0 < --y; ) {}
        } catch (aa) {
            a += 1, /[abc4]/g.exec((a = 1 + a, ((("object" & 38..toString()) <= NaN) / (Object.isExtensible(aa) && (aa[/[abc4]/g.exec((a = 1 + a, 
            (1 ^ (Object.isExtensible(S) && (S[a = 1 + a, (0 >> "bar" + undefined) - (0 === (Object.isExtensible(S) && (S.foo %= -0)))] &&= "a" >> {})) ^ NaN / [] << (Object.isExtensible(S) && ({
                set: S[a = 1 + a, a += 1, -.5 >>> (Object.isExtensible(S) && (S.then += !1))]
            } = {
                set: NaN
            })) || t || 5).toString()))] **= (24..toString() - -4) % (a += 1, "object"))) || t || 5).toString())), 
            a = 1 + a;
        }
        break;

      case t = i:
        --t, i++, a = a + 1 + 1;
    }
    for (var v = 5; (a += 1) + (i++ + (f && f[i++ + (f && "function" == typeof f.foo && 0 <= --n && f.foo("function" == typeof f && 0 <= --n && f((a += 1) + !(!(23..toString() + Infinity) >>> ("" <= 24..toString()) - (3 != 23..toString())))))])) && 0 < v; --v) {
        if (e && e[--t + i]) {
            for (var j = 5; i++ + (f && "function" == typeof f.Infinity && 0 <= --n && f.Infinity([ (a = 1 + a, 
            (Object.isExtensible(f) && (f["in"] = "function" === {} != 0 < 24..toString())) ^ ("c" !== Infinity) < NaN), (a = 1 + a, 
            1 !== NaN != (!1 | {} / 5)), (a = 1 + a, a += 1, e -= {} < (2 < 24..toString())) ])) && 0 < j; --j) {
                t >>>= i;
            }
        }
        i++;
    }
    break;

  case i++ + !(-4 ^ (Object.isExtensible(f) && ({
        [(a = 1 + a, ({} <= !1 ^ null ^ NaN) > (3 ^ {}) / 27)]: f["null"]
    } = {
        foo: 2 ^ 2 === [ , 0 ].length
    }))):
}

for (var x = 5; 0 < x; --x) {
    for (var h = 5; "function" == typeof f8 && 0 <= --n && f8("b") && 0 < --h; ) {
        a += 1;
    }
}

console.log(null, i, t, a, Infinity, NaN, undefined);
```
```
original result:
null 109 107 59 Infinity NaN undefined

uglified result:
ReferenceError: aa is not defined
    at [stdin]:192:342
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
```
```js
// reduced test case (output will differ)

// (beautified)
while (function() {
    switch (0) {
      case arguments_1:
        var arguments_1 = function a_2() {};
        try {
            arguments_1 <<= 0;
        } catch (a_2) {
            a_2[arguments_1];
        }
    }
}()) {}
// output: 
// minify: ReferenceError: b is not defined
// options: {
//   "ie": true,
//   "module": true,
//   "output": {
//     "semicolons": false,
//     "v8": true
//   },
//   "toplevel": true,
//   "validate": true
// }
```
```
minify(options):
{
  "ie": true,
  "module": true,
  "output": {
    "semicolons": false,
    "v8": true
  },
  "toplevel": true
}

Suspicious compress options:
  dead_code
  evaluate
  inline
  loops
  sequences
  side_effects

Suspicious options:
  ie
  rename
  toplevel
```



Discussion / hints:

Fix patch:
diff --git a/lib/compress.js b/lib/compress.js
index 9cf80de5d0..47dd5ba7c2 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -14368,6 +14368,7 @@ Compressor.prototype.compress = function(node) {
                 if (!all(def.orig, function(sym) {
                     if (sym instanceof AST_SymbolConst) return false;
                     if (sym instanceof AST_SymbolFunarg) return !sym.unused && def.scope.resolve() !== fn;
+                    if (sym instanceof AST_SymbolLambda) return !compressor.option("ie") || sym.scope === def.scope;
                     if (sym instanceof AST_SymbolLet) return false;
                     return true;
                 })) return;


Test patch:
diff --git a/test/compress/ie.js b/test/compress/ie.js
index 60c48c429d..8eb139b5e7 100644
--- a/test/compress/ie.js
+++ b/test/compress/ie.js
@@ -3474,3 +3474,40 @@ issue_5350_ie: {
     }
     expect_stdout: "undefined 42"
 }
+
+issue_5958: {
+    options = {
+        dead_code: true,
+        evaluate: true,
+        ie: true,
+        inline: true,
+        loops: true,
+        sequences: true,
+        toplevel: true,
+    }
+    input: {
+        "use strict";
+        while (function() {
+            if (a === console.log("PASS")) {
+                var a = function b() {};
+                try {
+                    a++;
+                } catch (b) {
+                    b[a];
+                }
+            }
+        }());
+    }
+    expect: {
+        "use strict";
+        if (a = void 0, a === console.log("PASS")) {
+            var a = function b() {};
+            try {
+                a++;
+            } catch (b) {
+                b[a];
+            }
+        }
+    }
+    expect_stdout: "PASS"
+}