fix typeof side-effects (#1669)

`has_side_effects()` does not take `typeof`'s magical power of not tripping over undeclared variable into account.

fixes #1668
This commit is contained in:
Alex Lam S.L
2017-03-25 17:40:18 +08:00
committed by GitHub
parent 8ca2401ebe
commit 6e86ee950d
2 changed files with 14 additions and 2 deletions

View File

@@ -3013,10 +3013,10 @@ merge(Compressor.prototype, {
// typeof always returns a non-empty string, thus it's // typeof always returns a non-empty string, thus it's
// always true in booleans // always true in booleans
compressor.warn("Boolean expression always true [{file}:{line},{col}]", self.start); compressor.warn("Boolean expression always true [{file}:{line},{col}]", self.start);
return make_node(AST_Seq, self, { return (e instanceof AST_SymbolRef ? make_node(AST_True, self) : make_node(AST_Seq, self, {
car: e, car: e,
cdr: make_node(AST_True, self) cdr: make_node(AST_True, self)
}).optimize(compressor); })).optimize(compressor);
} }
} }
// avoids infinite recursion of numerals // avoids infinite recursion of numerals

View File

@@ -48,3 +48,15 @@ typeof_in_boolean_context: {
foo(); foo();
} }
} }
issue_1668: {
options = {
booleans: true,
}
input: {
if (typeof bar);
}
expect: {
if (!0);
}
}