From aa37b196989edc13988ab225e4a7c954565e39eb Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 7 Jun 2020 06:48:29 +0100 Subject: [PATCH] fix corner case in `unused` (#3963) fixes #3962 --- lib/compress.js | 2 +- test/compress/drop-unused.js | 65 ++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index 6aa81a52..749abef5 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4521,7 +4521,7 @@ merge(Compressor.prototype, { var index = indexOf_assign(sym, def); if (index >= 0) assign_in_use[sym.id][index] = assign; sym.eliminated++; - return assign.transform(tt); + return assign; })); } else if (head.length > 0 || tail.length > 0) { node.definitions = head.concat(tail); diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js index a4a8595b..8c912a57 100644 --- a/test/compress/drop-unused.js +++ b/test/compress/drop-unused.js @@ -2690,3 +2690,68 @@ issue_3956: { "1", ] } + +issue_3962_1: { + options = { + evaluate: true, + keep_fargs: "strict", + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + var a = 0; + function f(b, c) { + do { + var d = console + e, e = 0..toString() === b; + } while (0); + if (c) console.log("PASS"); + } + var a = f(a--, 1); + a; + } + expect: { + var a = 0; + a = (function(c) { + do { + console; + 0..toString(); + } while (0); + if (c) console.log("PASS"); + })((a--, 1)); + void 0; + } + expect_stdout: "PASS" +} + +issue_3962_2: { + options = { + keep_fargs: "strict", + reduce_vars: true, + side_effects: true, + toplevel: true, + unused: true, + } + input: { + var a = 0; + function f(b, c) { + do { + var d = console + e, e = 0..toString() === b; + } while (0); + if (c) console.log("PASS"); + } + var a = f(a--, 1); + a; + } + expect: { + var a = 0; + a = (function(c) { + do { + console; + 0..toString(); + } while (0); + if (c) console.log("PASS"); + })((a--, 1)); + } + expect_stdout: "PASS" +} -- 2.34.1