diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-05-10 01:22:44 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-10 01:22:44 +0800 |
commit | 5476cb8f05d0e7d402d583ef726e743451555c10 (patch) | |
tree | 41a45da197ce1c52387d7bf738ebed552814751b | |
parent | 6a30e1d6bed66512d33dbb83adc954b43fe2823e (diff) | |
download | tracifyjs-5476cb8f05d0e7d402d583ef726e743451555c10.tar.gz tracifyjs-5476cb8f05d0e7d402d583ef726e743451555c10.zip |
fix corner case in `inline` (#3401)
fixes #3400
-rw-r--r-- | lib/compress.js | 1 | ||||
-rw-r--r-- | test/compress/collapse_vars.js | 12 | ||||
-rw-r--r-- | test/compress/drop-unused.js | 2 | ||||
-rw-r--r-- | test/compress/functions.js | 56 |
4 files changed, 60 insertions, 11 deletions
diff --git a/lib/compress.js b/lib/compress.js index 4db202a3..418b1d54 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -6102,7 +6102,6 @@ merge(Compressor.prototype, { })); } else { value = fixed.optimize(compressor); - if (value === fixed) value = fixed.clone(true); } def.replaced++; return value; diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 6e0afc6e..1862687a 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -3497,10 +3497,10 @@ issue_2437_1: { return Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {}), result; } - var req, detectFunc = function(){}; - (req = new XMLHttpRequest()).onreadystatechange = detectFunc; - result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc; - return req.onreadystatechange = null, result; + var req = new XMLHttpRequest(), detectFunc = function(){}; + return req.onreadystatechange = detectFunc, + result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc, + req.onreadystatechange = null, result; }()); } } @@ -3545,8 +3545,8 @@ issue_2437_2: { if (xhrDesc) return (req = new XMLHttpRequest()).onreadystatechange, Object.defineProperty(XMLHttpRequest.prototype, "onreadystatechange", xhrDesc || {}); - var req; - (req = new XMLHttpRequest).onreadystatechange = function(){}, + var req = new XMLHttpRequest(); + req.onreadystatechange = function(){}, req[SYMBOL_FAKE_ONREADYSTATECHANGE_1], req.onreadystatechange = null; }(); diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js index 9286532b..0869749d 100644 --- a/test/compress/drop-unused.js +++ b/test/compress/drop-unused.js @@ -797,6 +797,7 @@ assign_chain: { issue_1583: { options = { keep_fargs: true, + passes: 2, reduce_funcs: true, reduce_vars: true, unused: true, @@ -1144,6 +1145,7 @@ var_catch_toplevel: { options = { conditionals: true, negate_iife: true, + passes: 2, reduce_funcs: true, reduce_vars: true, side_effects: true, diff --git a/test/compress/functions.js b/test/compress/functions.js index e12ce3e2..21146457 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -2860,10 +2860,10 @@ issue_2437: { result; } function detectFunc() {} - var req; - (req = new XMLHttpRequest()).onreadystatechange = detectFunc; - result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc; - return req.onreadystatechange = null, result; + var req = new XMLHttpRequest(); + return req.onreadystatechange = detectFunc, + result = req[SYMBOL_FAKE_ONREADYSTATECHANGE_1] === detectFunc, + req.onreadystatechange = null, result; }()); } } @@ -3065,3 +3065,51 @@ class_iife: { } expect_stdout: "PASS" } + +issue_3400: { + options = { + collapse_vars: true, + inline: true, + reduce_funcs: true, + reduce_vars: true, + unused: true, + } + input: { + (function(f) { + console.log(f()()[0].p); + })(function() { + function g() { + function h(u) { + var o = { + p: u + }; + return console.log(o[g]), o; + } + function e() { + return [ 42 ].map(function(v) { + return h(v); + }); + } + return e(); + } + return g; + }); + } + expect: { + void console.log(function g() { + function e() { + return [42].map(function(v) { + return o = { + p: v + }, console.log(o[g]) , o; + var o; + }); + } + return e(); + }()[0].p); + } + expect_stdout: [ + "undefined", + "42", + ] +} |