From e61bc34eb18972d95159a6c2b27b133ea370e41f Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Fri, 19 Jun 2020 19:19:37 +0100 Subject: [PATCH] fix corner case in `collapse_vars` (#4002) fixes #4001 --- lib/compress.js | 2 -- test/compress/ie8.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index b312c64dd0..0e11ba96f3 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1500,7 +1500,6 @@ merge(Compressor.prototype, { can_replace = false; var after = stop_after; var if_hit = stop_if_hit; - var rhs_fn = scan_rhs; for (var i = 0; !abort && i < fn.body.length; i++) { var stat = fn.body[i]; if (stat instanceof AST_Return) { @@ -1509,7 +1508,6 @@ merge(Compressor.prototype, { } stat.transform(scanner); } - scan_rhs = rhs_fn; stop_if_hit = if_hit; stop_after = after; can_replace = replace; diff --git a/test/compress/ie8.js b/test/compress/ie8.js index c0049766e4..df06c62509 100644 --- a/test/compress/ie8.js +++ b/test/compress/ie8.js @@ -2559,3 +2559,37 @@ issue_3999: { "1", ] } + +issue_4001: { + options = { + collapse_vars: true, + ie8: true, + inline: true, + reduce_vars: true, + sequences: true, + toplevel: true, + unused: true, + } + input: { + console.log(function(a) { + function f() { + return a; + var b; + } + var c = f(); + (function g() { + c[42]; + f; + })(); + (function a() {}); + }(42)); + } + expect: { + function f() { + return a; + } + var a; + console.log((a = 42, void f()[42], void function a() {})); + } + expect_stdout: "undefined" +}