From: Alex Lam S.L Date: Wed, 13 Mar 2019 00:46:03 +0000 (+0800) Subject: fix corner case in `arguments` & `reduce_vars` (#3331) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=d4ac84b25518740959df18d0ed057bd0c6cba302;p=UglifyJS.git fix corner case in `arguments` & `reduce_vars` (#3331) fixes #3282 --- diff --git a/lib/compress.js b/lib/compress.js index 9109a696..75914b36 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -6334,8 +6334,8 @@ merge(Compressor.prototype, { && expr instanceof AST_SymbolRef && expr.name == "arguments" && expr.definition().orig.length == 1 - && (fn = expr.scope) instanceof AST_Lambda - && prop instanceof AST_Number) { + && prop instanceof AST_Number + && (fn = expr.scope) === compressor.find_parent(AST_Lambda)) { var index = prop.getValue(); var argname = fn.argnames[index]; if (argname && compressor.has_directive("use strict")) { diff --git a/test/compress/arguments.js b/test/compress/arguments.js index 8a19c8a6..fba271c7 100644 --- a/test/compress/arguments.js +++ b/test/compress/arguments.js @@ -404,3 +404,175 @@ issue_3273_global_strict_reduce_vars: { "1 0", ] } + +issue_3282_1: { + options = { + arguments: true, + reduce_funcs: true, + reduce_vars: true, + keep_fargs: false, + unused: true, + } + input: { + (function(t) { + return function() { + t(); + }; + })(function() { + 'use strict'; + function e() { + return arguments[0]; + } + e(); + e(); + })(); + } + expect: { + (function() { + return function() { + (function() { + "use strict"; + function e() { + return arguments[0]; + } + e(); + e(); + })(); + }; + })()(); + } + expect_stdout: true +} + +issue_3282_1_passes: { + options = { + arguments: true, + passes: 2, + reduce_funcs: true, + reduce_vars: true, + keep_fargs: false, + unused: true, + } + input: { + (function(t) { + return function() { + t(); + }; + })(function() { + 'use strict'; + function e() { + return arguments[0]; + } + e(); + e(); + })(); + } + expect: { + (function() { + return function() { + (function() { + "use strict"; + function e(argument_0) { + return argument_0; + } + e(); + e(); + })(); + }; + })()(); + } + expect_stdout: true +} + +issue_3282_2: { + options = { + arguments: true, + reduce_vars: true, + keep_fargs: false, + unused: true, + } + input: { + (function(f) { + f(); + })(function() { + return (function(t) { + return function() { + t(); + }; + })(function() { + 'use strict'; + function e() { + return arguments[0]; + } + e(); + e(); + })(); + }); + } + expect: { + (function() { + (function() { + return function(t) { + return function() { + t(); + }; + }(function() { + "use strict"; + function e() { + return arguments[0]; + } + e(); + e(); + })(); + })(); + })(); + } + expect_stdout: true +} + +issue_3282_2_passes: { + options = { + arguments: true, + passes: 2, + reduce_vars: true, + keep_fargs: false, + unused: true, + } + input: { + (function(f) { + f(); + })(function() { + return (function(t) { + return function() { + t(); + }; + })(function() { + 'use strict'; + function e() { + return arguments[0]; + } + e(); + e(); + })(); + }); + } + expect: { + (function() { + (function() { + return function(t) { + return function() { + t(); + }; + }(function() { + "use strict"; + function e(argument_0) { + return argument_0; + } + e(); + e(); + })(); + })(); + })(); + } + expect_stdout: true +}