Fix #105: property comparison to undefined is not always safe

This commit is contained in:
Richard Gibson
2013-01-23 23:52:04 -05:00
parent 297af47c89
commit 522566ea80
2 changed files with 19 additions and 1 deletions

View File

@@ -1739,7 +1739,8 @@ merge(Compressor.prototype, {
if (self.left instanceof AST_String if (self.left instanceof AST_String
&& self.left.value == "undefined" && self.left.value == "undefined"
&& self.right instanceof AST_UnaryPrefix && self.right instanceof AST_UnaryPrefix
&& self.right.operator == "typeof") { && self.right.operator == "typeof"
&& compressor.option("unsafe")) {
if (!(self.right.expression instanceof AST_SymbolRef) if (!(self.right.expression instanceof AST_SymbolRef)
|| !self.right.expression.undeclared()) { || !self.right.expression.undeclared()) {
self.left = self.right.expression; self.left = self.right.expression;

View File

@@ -0,0 +1,17 @@
typeof_eq_undefined: {
options = {
comparisons: true,
unsafe: false
};
input: { a = typeof b.c != "undefined" }
expect: { a = "undefined" != typeof b.c }
}
typeof_eq_undefined_unsafe: {
options = {
comparisons: true,
unsafe: true
};
input: { a = typeof b.c != "undefined" }
expect: { a = b.c !== void 0 }
}