added option for side-effect-free statements, fix test
This commit is contained in:
@@ -64,6 +64,7 @@ function Compressor(options, false_by_default) {
|
|||||||
if_return : !false_by_default,
|
if_return : !false_by_default,
|
||||||
join_vars : !false_by_default,
|
join_vars : !false_by_default,
|
||||||
cascade : !false_by_default,
|
cascade : !false_by_default,
|
||||||
|
side_effects : !false_by_default,
|
||||||
|
|
||||||
warnings : true,
|
warnings : true,
|
||||||
global_defs : {}
|
global_defs : {}
|
||||||
@@ -998,9 +999,11 @@ merge(Compressor.prototype, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
OPT(AST_SimpleStatement, function(self, compressor){
|
OPT(AST_SimpleStatement, function(self, compressor){
|
||||||
if (!self.body.has_side_effects()) {
|
if (compressor.option("side_effects")) {
|
||||||
compressor.warn("Dropping side-effect-free statement [{file}:{line},{col}]", self.start);
|
if (!self.body.has_side_effects()) {
|
||||||
return make_node(AST_EmptyStatement, self);
|
compressor.warn("Dropping side-effect-free statement [{file}:{line},{col}]", self.start);
|
||||||
|
return make_node(AST_EmptyStatement, self);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
});
|
});
|
||||||
@@ -1153,7 +1156,7 @@ merge(Compressor.prototype, {
|
|||||||
operator: "&&",
|
operator: "&&",
|
||||||
left: self.condition,
|
left: self.condition,
|
||||||
right: self.body.condition
|
right: self.body.condition
|
||||||
});
|
}).transform(compressor);
|
||||||
self.body = self.body.body;
|
self.body = self.body.body;
|
||||||
}
|
}
|
||||||
if (aborts(self.body)) {
|
if (aborts(self.body)) {
|
||||||
|
|||||||
@@ -124,3 +124,20 @@ ifs_5: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ifs_6: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
comparisons: true
|
||||||
|
};
|
||||||
|
input: {
|
||||||
|
if (!foo && !bar && !baz && !boo) {
|
||||||
|
x = 10;
|
||||||
|
} else {
|
||||||
|
x = 20;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
x = foo || bar || baz || boo ? 20 : 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user