diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-12-29 10:58:29 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-29 18:58:29 +0800 |
commit | 10a71c182bc4b992c91863fe0eb50a1afdae8a6f (patch) | |
tree | 4c87d141c5a66a32eeb53875e74fa92c958295e8 | |
parent | ddc0ed7072ed460f0121a700a6e7fde8fe28400a (diff) | |
download | tracifyjs-10a71c182bc4b992c91863fe0eb50a1afdae8a6f.tar.gz tracifyjs-10a71c182bc4b992c91863fe0eb50a1afdae8a6f.zip |
fix corner case in `arguments` (#4477)
fixes #4476
-rw-r--r-- | lib/compress.js | 32 | ||||
-rw-r--r-- | test/compress/arrows.js | 22 |
2 files changed, 40 insertions, 14 deletions
diff --git a/lib/compress.js b/lib/compress.js index 103f47f1..0369b63d 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -10173,22 +10173,26 @@ merge(Compressor.prototype, { var argname = fn.argnames[index]; if (def.deleted && def.deleted[index]) { argname = null; - } else if (argname && !(argname instanceof AST_SymbolFunarg)) { - argname = null; - } else if (argname && (compressor.has_directive("use strict") - || fn.name - || !(fn_parent instanceof AST_Call && index < fn_parent.args.length) - || !all(fn.argnames, function(argname) { - return argname instanceof AST_SymbolFunarg; - }))) { - var arg_def = argname.definition(); - if (!compressor.option("reduce_vars") - || def.reassigned - || arg_def.assignments - || arg_def.orig.length > 1) { + } else if (argname) { + var arg_def; + if (!(argname instanceof AST_SymbolFunarg)) { argname = null; + } else if (expr.scope.find_variable(argname.name) !== (arg_def = argname.definition())) { + argname = null; + } else if (compressor.has_directive("use strict") + || fn.name + || !(fn_parent instanceof AST_Call && index < fn_parent.args.length) + || !all(fn.argnames, function(argname) { + return argname instanceof AST_SymbolFunarg; + })) { + if (!compressor.option("reduce_vars") + || def.reassigned + || arg_def.assignments + || arg_def.orig.length > 1) { + argname = null; + } } - } else if (!argname && index < fn.argnames.length + 5 && compressor.drop_fargs(fn, fn_parent)) { + } else if (index < fn.argnames.length + 5 && compressor.drop_fargs(fn, fn_parent)) { while (index >= fn.argnames.length) { argname = fn.make_var(AST_SymbolFunarg, fn, "argument_" + fn.argnames.length); fn.argnames.push(argname); diff --git a/test/compress/arrows.js b/test/compress/arrows.js index 990090b2..6d9f89d1 100644 --- a/test/compress/arrows.js +++ b/test/compress/arrows.js @@ -616,3 +616,25 @@ issue_4448: { expect_stdout: "PASS" node_version: ">=4" } + +issue_4476: { + options = { + arguments: true, + } + input: { + (function(a, b) { + (a => { + console.log(arguments[0], a); + })(b); + })("foo", "bar"); + } + expect: { + (function(a, b) { + (a => { + console.log(arguments[0], a); + })(b); + })("foo", "bar"); + } + expect_stdout: "foo bar" + node_version: ">=4" +} |