enhance unsafe_math (#4093)

This commit is contained in:
Alex Lam S.L
2020-09-04 03:14:39 +01:00
committed by GitHub
parent 6e235602fb
commit 226aa1f76b
2 changed files with 24 additions and 6 deletions

View File

@@ -7556,13 +7556,15 @@ merge(Compressor.prototype, {
&& self.left.is_number(compressor)) {
if (self.left.left instanceof AST_Constant) {
var lhs = make_binary(self.left, self.operator, self.left.left, self.right, self.left.left.start, self.right.end);
self = make_binary(self, self.left.operator, lhs, self.left.right);
self = make_binary(self, self.left.operator, try_evaluate(compressor, lhs), self.left.right);
} else if (self.left.right instanceof AST_Constant) {
var rhs = make_binary(self.left, align(self.left.operator, self.operator), self.left.right, self.right, self.left.right.start, self.right.end);
if (self.left.operator != "-"
|| !self.right.value
|| rhs.evaluate(compressor)
|| !self.left.left.is_negative_zero()) {
var op = align(self.left.operator, self.operator);
var rhs = try_evaluate(compressor, make_binary(self.left, op, self.left.right, self.right));
if (rhs.is_constant()
&& !(self.left.operator == "-"
&& self.right.value != 0
&& +rhs.value == 0
&& self.left.left.is_negative_zero())) {
self = make_binary(self, self.left.operator, self.left.left, rhs);
}
}