has_side_effects() should take AST_Switch.expression into account (#1699)

fixes #1698
This commit is contained in:
Alex Lam S.L
2017-03-27 18:09:35 +08:00
committed by GitHub
parent 581630e0a7
commit c526da59a1
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"
}