Repository: mishoo/UglifyJS (JavaScript)

Issue:
ufuzz failure
```js
// original code
// (beautified)
var _calls_ = 10, a = 100, b = 10, c = 0;

function f0(foo_1, bar, yield_1) {
    if ((() => {
        for (var brake2 = 5; (Infinity_1 => {
            c = c + 1;
            {
                var brake4 = 5;
                L15337: do {
                    switch (a++ + !(Infinity_1 && (Infinity_1.async *= (Infinity_1 *= ("function" - "b") / ("bar" ^ false)) << (null << 5) / (-3 / 24..toString())))) {
                      case typeof f0 == "function" && --_calls_ >= 0 && f0():
                        break;

                      case a++ + (typeof f0 == "function" && --_calls_ >= 0 && f0()):
                        c = 1 + c, ("bar" - 22, "number" ^ "object") | false >>> "function" < (-3, 
                        /[a2][^e]+$/);
                        c = 1 + c, ("number" <= -3) % (-4 || 24..toString()) < (null != "a" && (yield_1 && (yield_1.undefined = 2 << this)));
                        break;

                      case --b + (Infinity_1 && Infinity_1[c = 1 + c, c = c + 1, 
                        "object" / Infinity < (-3 >= -1)]):
                        break;

                      case --b + b--:
                        c = 1 + c, ("b" == -1 && "bar" >= 3) ^ /[a2][^e]+$/ - /[a2][^e]+$/ > ("a" > -4);
                        c = 1 + c, (null ^ "c") % (-3 === "function") * -(0 >> "number");
                    }
                } while (--b && --brake4 > 0);
            }
            --b + --b;
            {
                var undefined_2 = function f1(arguments) {
                    c = 1 + c, (arguments && (arguments[b + 1 - .1 - .1 - .1] += /[a2][^e]+$/ >= true && /[a2][^e]+$/ & "b")) ^ (bar && ([ bar.in ] = [ 22 || 23..toString() ])) >= ("undefined" == "object");
                    c = 1 + c, (arguments && (arguments[(c = c + 1) + "undefined"] %= ({}, 
                    -0) & false + 0)) - (void 24..toString() <= (null < 4));
                }(a++ + (bar && bar.b), (c = c + 1) + --b);
            }
        })(--b + ("bar" >>> "bar" > ("foo" | []) <= ("b" !== Infinity) / ("b" - ""))) && brake2 > 0; --brake2) {
            switch (0 === 1 ? a : b) {
              default:
                c = c + 1;

              case {
                    get: (c = c + 1) + (b = a),
                    done: --b + {
                        foo: (c = 1 + c, (yield_1 && (yield_1[--b] = ("c", 3) == (1 | [ , 0 ].length === 2))) * (0 / NaN & Infinity === "bar")),
                        "": (c = 1 + c, ({} + [ , 0 ][1] && (yield_1 && (yield_1.done = null != 2))) ^ (-4 >= null) + (yield_1 && (yield_1.undefined = "b" ^ 5))),
                        length: (c = 1 + c, ((c = c + 1, -2) << (c = c + 1, -0)) * (bar = -1 + 2 > ("a" >= 23..toString()))),
                        ...foo_1,
                        b: (c = 1 + c, (-4 < this ^ "a" !== -3) != (-5 >> "b" | 24..toString() % -2))
                    }.done
                }[typeof bar]:
                {
                    var expr16 = (c = c + 1) + delete a;
                    for (var key16 in expr16) {
                        c = 1 + c;
                        var b_1 = expr16[key16];
                        c = c + 1;
                    }
                }
                {
                    var expr18 = (c = c + 1) + /[abc4]/g.exec((typeof f0 == "function" && --_calls_ >= 0 && f0() || b || 5).toString());
                    for (var key18 in expr18) {
                        c = 1 + c;
                        var await = expr18[key18];
                        var await_1;
                    }
                }
                break;

              case a--:
                {
                    var b = function f2(let_1, bar_2, yield_1) {
                        const NaN_2 = a++ + (c = 1 + c, 2 !== [ , 0 ][1] !== (24..toString() ^ null) || ("function" && true) < (-3 < -1));
                        c = 1 + c, ("foo" % 24..toString() >= false * [ , 0 ][1]) << (-2 - 38..toString() && (yield_1 && (yield_1.foo += "bar" && [ , 0 ].length === 2)));
                        c = 1 + c, (3 == -1 ^ -1 == -3) == (c = c + 1, [ , 0 ][1] && [ , 0 ][1]);
                    }();
                }
                try {
                    var undefined_1 = ((c = 1 + c, ((NaN === Infinity) <= (2 && /[a2][^e]+$/)) - (([ , 0 ][1], 
                    null) && 1 | 38..toString())) || a || 3).toString();
                } finally {
                    {
                    }
                    try {
                        c = 1 + c, -5 / "undefined" && [ , 0 ].length === 2 === this && (22, 
                        NaN, yield_1 && (yield_1.set = "undefined" !== -2));
                    } catch (undefined_1_2) {
                    }
                }
                break;

              case (c = c + 1) + ((b += null !== this) >>> (2 ^ "b") || (-5 !== 38..toString()) > ("foo" === true)):
                break;
            }
        }
        {
            var expr28 = yield_1 = b += a;
            for (var key28 in expr28) {
                c = 1 + c;
                var c_2 = expr28[key28];
                (c = c + 1) + bar;
            }
        }
        c = c + 1;
    })(NaN, 23..toString(), "b")) {
        return;
    }
    var a_2;
}

var Infinity_2 = f0();

console.log(null, a, b, c, Infinity, NaN, undefined);
```
```
// !!! uglify failed !!!
TypeError: Cannot read property 'resolve' of undefined
    at eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:17881:40)
    at all (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:153:14)
    at same_scope (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:17880:16)
    at TreeWalker.eval [as callback] (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:9217:89)
    at TreeWalker.visit (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2323:25)
    at AST_SymbolRef.walk (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:402:17)
    at eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:1789:23)
    at TreeWalker.visit (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2324:31)
    at AST_Assign.walk (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:1788:17)
    at get_lvalues (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:9277:22)
    at collapse (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:8374:35)
    at tighten_body (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:8034:21)
    at eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:12014:21)
    at AST_BlockStatement.eval [as optimize] (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:19776:19)
    at eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:15053:80)
    at AST_For.eval [as optimize] (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:19776:19)
    at Compressor.eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:6308:20)
    at AST_For.eval [as transform] (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2656:31)
    at AST_For.ctor.transform (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:504:34)
    at eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2474:25)
    at List (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:103:23)
    at do_list (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2473:16)
    at transform_arrow (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2563:25)
    at Compressor.eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:6303:5)
    at AST_Arrow.eval [as transform] (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2656:31)
    at AST_Arrow.ctor.transform (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:504:34)
    at eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2578:43)
    at Compressor.eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:6303:5)
    at AST_Call.eval [as transform] (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2656:31)
    at AST_Call.ctor.transform (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:504:34)
    at eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2519:41)
    at Compressor.eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:6303:5)
    at AST_If.eval [as transform] (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2656:31)
    at AST_If.ctor.transform (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:504:34)
    at eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2474:25)
    at List (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:103:23)
    at do_list (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2473:16)
    at eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2555:21)
    at Compressor.eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:6303:5)
    at AST_Defun.eval [as transform] (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2656:31)
    at AST_Defun.ctor.transform (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:504:34)
    at eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2474:25)
    at List (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:103:23)
    at do_list (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2473:16)
    at eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2487:21)
    at Compressor.eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:6303:5)
    at AST_Toplevel.eval [as transform] (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2656:31)
    at AST_Toplevel.ctor.transform (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:504:34)
    at Compressor.compress (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:6343:21)
    at Object.minify (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:23652:57)
    at D:\a\UglifyJS\UglifyJS\test\ufuzz\index.js:2481:32
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (D:\a\UglifyJS\UglifyJS\test\ufuzz\index.js:2477:20)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)
    at bootstrap_node.js:625:3
```
```js
// reduced test case (output will differ)

// (beautified)
() => {
    for (var brake2 = 5; (() => {
        b;
        var undefined_2 = function f1(arguments) {
            arguments[0];
        }();
    })(); 0) {}
};
// minify error: TypeError: Cannot read property 'resolve' of undefined
//     at join_var_assign (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:9966:31)
//     at join_assigns (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:9922:48)
//     at join_consecutive_vars (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:10111:33)
//     at tighten_body (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:8030:21)
//     at eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:12014:21)
//     at AST_BlockStatement.eval [as optimize] (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:19776:19)
//     at eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:15053:80)
//     at AST_For.eval [as optimize] (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:19776:19)
//     at Compressor.eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:6308:20)
//     at AST_For.eval [as transform] (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2656:31)
//     at AST_For.ctor.transform (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:504:34)
//     at eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2474:25)
//     at List (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:103:23)
//     at do_list (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2473:16)
//     at transform_arrow (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2563:25)
//     at Compressor.eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:6303:5)
//     at AST_Arrow.eval [as transform] (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2656:31)
//     at AST_Arrow.ctor.transform (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:504:34)
//     at eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2484:31)
//     at Compressor.eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:6303:5)
//     at AST_SimpleStatement.eval [as transform] (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2656:31)
//     at AST_SimpleStatement.ctor.transform (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:504:34)
//     at eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2474:25)
//     at List (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:103:23)
//     at do_list (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2473:16)
//     at eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2487:21)
//     at Compressor.eval (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:6303:5)
//     at AST_Toplevel.eval [as transform] (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:2656:31)
//     at AST_Toplevel.ctor.transform (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:504:34)
//     at Compressor.compress (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:6343:21)
//     at Object.minify (eval at <anonymous> (D:\a\UglifyJS\UglifyJS\tools\node.js:18:1), <anonymous>:23652:57)
//     at test_minify (D:\a\UglifyJS\UglifyJS\test\reduce.js:780:22)
//     at reduce_test (D:\a\UglifyJS\UglifyJS\test\reduce.js:610:16)
//     at log (D:\a\UglifyJS\UglifyJS\test\ufuzz\index.js:2230:23)
//     at D:\a\UglifyJS\UglifyJS\test\ufuzz\index.js:2578:80
//     at Array.forEach (<anonymous>)
//     at Object.<anonymous> (D:\a\UglifyJS\UglifyJS\test\ufuzz\index.js:2477:20)
//     at Module._compile (module.js:653:30)
//     at Object.Module._extensions..js (module.js:664:10)
//     at Module.load (module.js:566:32)
//     at tryModuleLoad (module.js:506:12)
//     at Function.Module._load (module.js:498:3)
//     at Function.Module.runMain (module.js:694:10)
//     at startup (bootstrap_node.js:204:16)
//     at bootstrap_node.js:625:3
// options: {
//   "mangle": false,
//   "output": {
//     "v8": true
//   },
//   "validate": true
// }
```
```
minify(options):
{
  "mangle": false,
  "output": {
    "v8": true
  }
}

Suspicious compress options:
  collapse_vars
  dead_code
  evaluate
  inline
  loops
  sequences
  unused
```


Discussion:

Patch:
diff --git a/lib/scope.js b/lib/scope.js
index ad31f306d87..90301d9a269 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -469,6 +469,7 @@ AST_Lambda.DEFMETHOD("init_vars", function(parent_scope) {
     this.uses_arguments = false;
     this.def_variable(new AST_SymbolFunarg({
         name: "arguments",
+        scope: this,
         start: this.start,
         end: this.end,
     }));


Test patch:
diff --git a/test/compress/arrows.js b/test/compress/arrows.js
index 389b877a223..9691648e571 100644
--- a/test/compress/arrows.js
+++ b/test/compress/arrows.js
@@ -1072,3 +1072,37 @@ issue_5414_2: {
     expect_stdout: true
     node_version: ">=4"
 }
+
+issue_5416: {
+    options = {
+        dead_code: true,
+        evaluate: true,
+        inline: true,
+        loops: true,
+        unused: true,
+    }
+    input: {
+        var f = () => {
+            while ((() => {
+                console;
+                var a = function g(arguments) {
+                    console.log(arguments);
+                }();
+            })());
+        };
+        f();
+    }
+    expect: {
+        var f = () => {
+            {
+                arguments = void 0;
+                console;
+                console.log(arguments);
+                var arguments;
+            }
+        };
+        f();
+    }
+    expect_stdout: "undefined"
+    node_version: ">=4"
+}