diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-02-22 07:44:16 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-22 15:44:16 +0800 |
commit | f9a2a9d78e8437d8b9591e97ab280e20b9442b35 (patch) | |
tree | 29ce60bf6d3f52abdf93bfe87587389ac92b1301 | |
parent | 960668ccdb8a3498ee61387648c457f242cfe29c (diff) | |
download | tracifyjs-f9a2a9d78e8437d8b9591e97ab280e20b9442b35.tar.gz tracifyjs-f9a2a9d78e8437d8b9591e97ab280e20b9442b35.zip |
enhance `side_effects` (#4675)
-rw-r--r-- | lib/compress.js | 2 | ||||
-rw-r--r-- | test/compress/side_effects.js | 25 |
2 files changed, 25 insertions, 2 deletions
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" +} |