Skip to content

Commit

Permalink
drop property assignment to constants (#2612)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Dec 18, 2017
1 parent b29fc8b commit 0b0eac1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/compress.js
Expand Up @@ -1708,6 +1708,11 @@ merge(Compressor.prototype, {
return this.consequent._dot_throw(compressor)
|| this.alternative._dot_throw(compressor);
})
def(AST_Dot, function(compressor) {
if (!is_strict(compressor)) return false;
if (this.expression instanceof AST_Function && this.property == "prototype") return false;
return true;
});
def(AST_Sequence, function(compressor) {
return this.tail_node()._dot_throw(compressor);
});
Expand Down Expand Up @@ -3184,8 +3189,14 @@ merge(Compressor.prototype, {
}
});
def(AST_Assign, function(compressor){
this.write_only = !this.left.has_side_effects(compressor);
return this;
var left = this.left;
if (left.has_side_effects(compressor)) return this;
this.write_only = true;
while (left instanceof AST_PropAccess) {
left = left.expression;
}
if (left instanceof AST_Symbol) return this;
return this.right.drop_side_effect_free(compressor);
});
def(AST_Conditional, function(compressor){
var consequent = this.consequent.drop_side_effect_free(compressor);
Expand Down
40 changes: 40 additions & 0 deletions test/compress/properties.js
Expand Up @@ -1054,3 +1054,43 @@ issue_2513: {
"undefined undefined",
]
}

const_prop_assign_strict: {
options = {
pure_getters: "strict",
side_effects: true,
}
input: {
function Simulator() {
/abc/.index = 1;
this._aircraft = [];
}
(function() {}).prototype.destroy = x();
}
expect: {
function Simulator() {
this._aircraft = [];
}
x();
}
}

const_prop_assign_pure: {
options = {
pure_getters: true,
side_effects: true,
}
input: {
function Simulator() {
/abc/.index = 1;
this._aircraft = [];
}
(function() {}).prototype.destroy = x();
}
expect: {
function Simulator() {
this._aircraft = [];
}
x();
}
}

0 comments on commit 0b0eac1

Please sign in to comment.