@@ -4790,6 +4790,7 @@ merge(Compressor.prototype, {
|
|||||||
if (compressor.option("comparisons")) switch (self.operator) {
|
if (compressor.option("comparisons")) switch (self.operator) {
|
||||||
case "===":
|
case "===":
|
||||||
case "!==":
|
case "!==":
|
||||||
|
var is_strict_comparison = true;
|
||||||
if ((self.left.is_string(compressor) && self.right.is_string(compressor)) ||
|
if ((self.left.is_string(compressor) && self.right.is_string(compressor)) ||
|
||||||
(self.left.is_number(compressor) && self.right.is_number(compressor)) ||
|
(self.left.is_number(compressor) && self.right.is_number(compressor)) ||
|
||||||
(self.left.is_boolean() && self.right.is_boolean()) ||
|
(self.left.is_boolean() && self.right.is_boolean()) ||
|
||||||
@@ -4799,8 +4800,12 @@ merge(Compressor.prototype, {
|
|||||||
// XXX: intentionally falling down to the next case
|
// XXX: intentionally falling down to the next case
|
||||||
case "==":
|
case "==":
|
||||||
case "!=":
|
case "!=":
|
||||||
|
// void 0 == x => null == x
|
||||||
|
if (!is_strict_comparison && is_undefined(self.left, compressor)) {
|
||||||
|
self.left = make_node(AST_Null, self.left);
|
||||||
|
}
|
||||||
// "undefined" == typeof x => undefined === x
|
// "undefined" == typeof x => undefined === x
|
||||||
if (compressor.option("typeofs")
|
else if (compressor.option("typeofs")
|
||||||
&& self.left instanceof AST_String
|
&& self.left instanceof AST_String
|
||||||
&& self.left.value == "undefined"
|
&& self.left.value == "undefined"
|
||||||
&& self.right instanceof AST_UnaryPrefix
|
&& self.right instanceof AST_UnaryPrefix
|
||||||
|
|||||||
37
test/compress/issue-2871.js
Normal file
37
test/compress/issue-2871.js
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
comparison_with_undefined: {
|
||||||
|
options = {
|
||||||
|
comparisons: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
a == undefined;
|
||||||
|
a != undefined;
|
||||||
|
a === undefined;
|
||||||
|
a !== undefined;
|
||||||
|
|
||||||
|
undefined == a;
|
||||||
|
undefined != a;
|
||||||
|
undefined === a;
|
||||||
|
undefined !== a;
|
||||||
|
|
||||||
|
void 0 == a;
|
||||||
|
void 0 != a;
|
||||||
|
void 0 === a;
|
||||||
|
void 0 !== a;
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
null == a;
|
||||||
|
null != a;
|
||||||
|
void 0 === a;
|
||||||
|
void 0 !== a;
|
||||||
|
|
||||||
|
null == a;
|
||||||
|
null != a;
|
||||||
|
void 0 === a;
|
||||||
|
void 0 !== a;
|
||||||
|
|
||||||
|
null == a;
|
||||||
|
null != a;
|
||||||
|
void 0 === a;
|
||||||
|
void 0 !== a;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user