This commit is contained in:
Justin Lau 2013-05-08 06:00:40 -07:00
commit 70731c86cd
3 changed files with 58 additions and 11 deletions

View File

@ -1751,14 +1751,14 @@ merge(Compressor.prototype, {
// XXX: intentionally falling down to the next case // XXX: intentionally falling down to the next case
case "==": case "==":
case "!=": case "!=":
if (self.left instanceof AST_String if (compressor.option("unsafe")
&& self.left.value == "undefined" && self.left instanceof AST_UnaryPrefix
&& self.right instanceof AST_UnaryPrefix && self.left.operator == "typeof"
&& self.right.operator == "typeof" && self.right instanceof AST_String
&& compressor.option("unsafe")) { && self.right.value == "undefined") {
if (!(self.right.expression instanceof AST_SymbolRef) if (!(self.left.expression instanceof AST_SymbolRef)
|| !self.right.expression.undeclared()) { || !self.left.expression.undeclared()) {
self.left = self.right.expression; self.left = self.left.expression;
self.right = make_node(AST_Undefined, self.left).optimize(compressor); self.right = make_node(AST_Undefined, self.left).optimize(compressor);
if (self.operator.length == 2) self.operator += "="; if (self.operator.length == 2) self.operator += "=";
} }

View File

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

View File

@ -0,0 +1,48 @@
/**
* There was an incorrect sort behaviour documented in issue #143:
* (x = f()) <= x x >= (x = f())
*
* For example, let the equation be:
* (a = parseInt('100')) <= a
*
* If a was an integer and has the value of 99,
* (a = parseInt('100')) <= a 100 <= 100 true
*
* When transformed incorrectly:
* a >= (a = parseInt('100')) 99 >= 100 false
*/
tranformation_sort_order_equal: {
options = {
comparisons: true,
};
input: { (a = parseInt('100')) == a }
expect: { (a = parseInt('100')) == a }
}
tranformation_sort_order_unequal: {
options = {
comparisons: true,
};
input: { (a = parseInt('100')) != a }
expect: { (a = parseInt('100')) != a }
}
tranformation_sort_order_lesser_or_equal: {
options = {
comparisons: true,
};
input: { (a = parseInt('100')) <= a }
expect: { (a = parseInt('100')) <= a }
}
tranformation_sort_order_greater_or_equal: {
options = {
comparisons: true,
};
input: { (a = parseInt('100')) >= a }
expect: { (a = parseInt('100')) >= a }
}