Skip to content

Commit

Permalink
drop assignments to constant expressions only
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Jan 22, 2018
1 parent 5e2cd07 commit c293fcf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -3469,8 +3469,10 @@ merge(Compressor.prototype, {
while (left instanceof AST_PropAccess) {
left = left.expression;
}
if (left instanceof AST_Symbol) return this;
return this.right.drop_side_effect_free(compressor);
if (left.is_constant_expression(compressor.find_parent(AST_Scope))) {
return this.right.drop_side_effect_free(compressor);
}
return this;
});
def(AST_Conditional, function(compressor){
var consequent = this.consequent.drop_side_effect_free(compressor);
Expand Down
27 changes: 27 additions & 0 deletions test/compress/pure_getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,3 +694,30 @@ issue_2678: {
}
expect_stdout: "PASS"
}

issue_2838: {
options = {
pure_getters: true,
side_effects: true,
}
input: {
function f(a, b) {
(a || b).c = "PASS";
(function() {
return f(a, b);
}).prototype.foo = "bar";
}
var o = {};
f(null, o);
console.log(o.c);
}
expect: {
function f(a, b) {
(a || b).c = "PASS";
}
var o = {};
f(null, o);
console.log(o.c);
}
expect_stdout: "PASS"
}

0 comments on commit c293fcf

Please sign in to comment.