diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-03-13 08:46:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-13 08:46:03 +0800 |
commit | d4ac84b25518740959df18d0ed057bd0c6cba302 (patch) | |
tree | 8fd94440f9bde883c60fd819b55c09e4a024d486 | |
parent | e250396d7e9f494bc772bbee03c63a3912998b15 (diff) | |
download | tracifyjs-d4ac84b25518740959df18d0ed057bd0c6cba302.tar.gz tracifyjs-d4ac84b25518740959df18d0ed057bd0c6cba302.zip |
fix corner case in `arguments` & `reduce_vars` (#3331)
fixes #3282
-rw-r--r-- | lib/compress.js | 4 | ||||
-rw-r--r-- | test/compress/arguments.js | 172 |
2 files changed, 174 insertions, 2 deletions
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 +} |