From: Alex Lam S.L Date: Mon, 22 Feb 2021 07:44:16 +0000 (+0000) Subject: enhance `side_effects` (#4675) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=f9a2a9d78e8437d8b9591e97ab280e20b9442b35;p=UglifyJS.git enhance `side_effects` (#4675) --- diff --git a/lib/compress.js b/lib/compress.js index 0a89de7e..c6451012 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -8516,6 +8516,8 @@ merge(Compressor.prototype, { } }); return node; + } else if (!node.has_side_effects(compressor)) { + self.drop_side_effect_free = return_null; } } var arg_used, insert, in_loop, scope; diff --git a/test/compress/side_effects.js b/test/compress/side_effects.js index 994e884c..fd6cabc6 100644 --- a/test/compress/side_effects.js +++ b/test/compress/side_effects.js @@ -348,8 +348,6 @@ issue_3983_1: { } expect: { var a = "PASS"; - g(); - function g() {} console.log(a); } expect_stdout: "PASS" @@ -537,3 +535,26 @@ issue_4668: { } expect_stdout: "undefined" } + +drop_side_effect_free_call: { + options = { + inline: true, + reduce_vars: true, + side_effects: true, + toplevel: true, + } + input: { + function f(a) { + return "PA" + a; + } + f(42); + console.log(f("SS")); + } + expect: { + function f(a) { + return "PA" + a; + } + console.log(f("SS")); + } + expect_stdout: "PASS" +}