aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-01-18 22:34:48 +0000
committerGitHub <noreply@github.com>2021-01-19 06:34:48 +0800
commitb57bae4b9e528ec7aeea7fd5768295a559cb5e5d (patch)
tree9226c609aba9ff4a04a6e1b70432a94f93f073a9
parente23a10f7f96cda932c605988d2d99bb5225d18a5 (diff)
downloadtracifyjs-b57bae4b9e528ec7aeea7fd5768295a559cb5e5d.tar.gz
tracifyjs-b57bae4b9e528ec7aeea7fd5768295a559cb5e5d.zip
fix corner case in `reduce_vars` (#4569)
fixes #4568
-rw-r--r--lib/compress.js2
-rw-r--r--test/compress/ie8.js19
-rw-r--r--test/compress/reduce_vars.js29
3 files changed, 49 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 81511535..e33f4f3f 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -9733,7 +9733,7 @@ merge(Compressor.prototype, {
single_use = false;
}
if (single_use) fixed.parent_scope = self.scope;
- } else if (!fixed || !fixed.is_constant_expression()) {
+ } else if (!fixed || !fixed.is_constant_expression() || fixed.drop_side_effect_free(compressor)) {
single_use = false;
}
}
diff --git a/test/compress/ie8.js b/test/compress/ie8.js
index c28512ac..ed3950a0 100644
--- a/test/compress/ie8.js
+++ b/test/compress/ie8.js
@@ -2900,3 +2900,22 @@ issue_4250: {
}
expect_stdout: "0"
}
+
+issue_4568: {
+ options = {
+ ie8: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ console.log(typeof f, function(a) {
+ return a.length;
+ }([ function f() {} ]));
+ }
+ expect: {
+ console.log(typeof f, function(a) {
+ return a.length;
+ }([ function f() {} ]));
+ }
+ expect_stdout: "undefined 1"
+}
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index ea9efee0..185a39cf 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -7601,3 +7601,32 @@ issue_4188_2: {
}
expect_stdout: "number undefined"
}
+
+issue_4568: {
+ options = {
+ booleans: true,
+ conditionals: true,
+ dead_code: true,
+ evaluate: true,
+ loops: true,
+ passes: 2,
+ reduce_vars: true,
+ sequences: true,
+ unused: true,
+ }
+ input: {
+ (function(a) {
+ a && console.log("FAIL");
+ if (1)
+ do {
+ if (!console.log("PASS")) break;
+ } while (1);
+ })(!(0 !== delete NaN));
+ }
+ expect: {
+ (function(a) {
+ for (a && console.log("FAIL"), 1; console.log("PASS"); ) 1;
+ })(!(0 !== delete NaN));
+ }
+ expect_stdout: "PASS"
+}