aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-10-23 01:58:40 +0800
committerGitHub <noreply@github.com>2019-10-23 01:58:40 +0800
commit267bc70d3358170794938ab915c01092c9cf59e2 (patch)
tree35f477859944870af9bdf07b3813b99931c066d3
parenta53ab9937835f795c4714e981d10249e7829d2d4 (diff)
downloadtracifyjs-267bc70d3358170794938ab915c01092c9cf59e2.tar.gz
tracifyjs-267bc70d3358170794938ab915c01092c9cf59e2.zip
fix corner case in `unused` (#3517)
fixes #3515
-rw-r--r--lib/compress.js4
-rw-r--r--test/compress/drop-unused.js25
2 files changed, 28 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index a8bf0d9d..f7fedeb2 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3737,7 +3737,9 @@ merge(Compressor.prototype, {
def.value = null;
head.push(def);
} else {
- var value = def.value && def.value.drop_side_effect_free(compressor);
+ var value = def.value
+ && (sym.references.length != 1 || !sym.replaced)
+ && def.value.drop_side_effect_free(compressor);
if (value) {
AST_Node.warn("Side effects in initialization of unused variable {name} [{file}:{line},{col}]", template(def.name));
side_effects.push(value);
diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js
index 942762f9..833b8c61 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -2102,3 +2102,28 @@ issue_3497: {
}
expect_stdout: "undefined"
}
+
+issue_3515: {
+ options = {
+ collapse_vars: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ var c = 0;
+ (function() {
+ this[c++] = 0;
+ var expr20 = !0;
+ for (var key20 in expr20);
+ })();
+ console.log(c);
+ }
+ expect: {
+ var c = 0;
+ (function() {
+ for (var key20 in !(this[c++] = 0));
+ })();
+ console.log(c);
+ }
+ expect_stdout: "1"
+}