Skip to content

Commit

Permalink
fix corner case in unused (#3517)
Browse files Browse the repository at this point in the history
fixes #3515
  • Loading branch information
alexlamsl committed Oct 22, 2019
1 parent a53ab99 commit 267bc70
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/compress.js
Expand Up @@ -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);
Expand Down
25 changes: 25 additions & 0 deletions test/compress/drop-unused.js
Expand Up @@ -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"
}

0 comments on commit 267bc70

Please sign in to comment.