change undefined == x to null == x

fixes #2871
This commit is contained in:
Dan Wolff 2018-02-04 21:08:01 +01:00
parent e6a2e9e4d0
commit 7f67c56d64
2 changed files with 23 additions and 0 deletions

View File

@ -4858,6 +4858,12 @@ merge(Compressor.prototype, {
}
break;
}
// void 0 == x => null == x
if (compressor.option("comparisons") &&
(self.operator == "==" || self.operator == "!=") &&
is_undefined(self.left, compressor)) {
self.left = make_node_from_constant(null, self.left);
}
if (self.operator == "+" && compressor.in_boolean_context()) {
var ll = self.left.evaluate(compressor);
var rr = self.right.evaluate(compressor);

View File

@ -0,0 +1,17 @@
comparison_with_undefined: {
options = {
comparisons: true,
}
input: {
a == undefined
a != undefined
a === undefined
a !== undefined
}
expect: {
null == a
null != a
void 0 === a
void 0 !== a
}
}