has_side_effects() should take AST_Switch.expression into account

fixes #1698
This commit is contained in:
alexlamsl 2017-03-27 17:33:32 +08:00
parent 581630e0a7
commit cb1811abf1
2 changed files with 27 additions and 2 deletions

View File

@ -1610,9 +1610,13 @@ merge(Compressor.prototype, {
def(AST_Block, function(compressor){
return any(this.body, compressor);
});
def(AST_Switch, function(compressor){
return this.expression.has_side_effects(compressor)
|| any(this.body, compressor);
});
def(AST_Case, function(compressor){
return any(this.body, compressor)
|| this.expression.has_side_effects(compressor);
return this.expression.has_side_effects(compressor)
|| any(this.body, compressor);
});
def(AST_Try, function(compressor){
return any(this.body, compressor)

View File

@ -593,3 +593,24 @@ if_switch_typeof: {
a;
}
}
issue_1698: {
options = {
side_effects: true,
}
input: {
var a = 1;
!function() {
switch (a++) {}
}();
console.log(a);
}
expect: {
var a = 1;
!function() {
switch (a++) {}
}();
console.log(a);
}
expect_stdout: "2"
}