Fix (typeof side_effect()) in boolean context

Fixes #1289 with suggestion by @rvanvelzen
This commit is contained in:
kzc
2016-10-02 10:46:09 -04:00
committed by Richard van Velzen
parent 4761d07e0b
commit fc9804b909
2 changed files with 28 additions and 0 deletions

View File

@@ -2314,6 +2314,12 @@ merge(Compressor.prototype, {
// typeof always returns a non-empty string, thus it's
// always true in booleans
compressor.warn("Boolean expression always true [{file}:{line},{col}]", self.start);
if (self.expression.has_side_effects(compressor)) {
return make_node(AST_Seq, self, {
car: self.expression,
cdr: make_node(AST_True, self)
});
}
return make_node(AST_True, self);
}
if (e instanceof AST_Binary && self.operator == "!") {