aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 8e116c6c..442df59d 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2899,7 +2899,19 @@ merge(Compressor.prototype, {
case ">=" : result = left >= right; break;
default : return this;
}
- return isNaN(result) && compressor.find_parent(AST_With) ? this : result;
+ if (isNaN(result)) return compressor.find_parent(AST_With) ? this : result;
+ if (compressor.option("unsafe_math")
+ && typeof result == "number"
+ && (this.operator == "+" || this.operator == "-")) {
+ var digits = Math.max(0, decimals(left), decimals(right));
+ if (digits < 21) return +result.toFixed(digits);
+ }
+ return result;
+
+ function decimals(operand) {
+ var match = /(\.[0-9]*)?(e.+)?$/.exec(+operand);
+ return (match[1] || ".").length - 1 - (match[2] || "").slice(1);
+ }
});
def(AST_Conditional, function(compressor, cached, depth) {
var condition = this.condition._eval(compressor, cached, depth);
@@ -5980,8 +5992,11 @@ merge(Compressor.prototype, {
// a + (b + c) => (a + b) + c
if (self.right instanceof AST_Binary
&& self.right.operator != "%"
+ && PRECEDENCE[self.right.operator] == PRECEDENCE[self.operator]
&& self.right.is_number(compressor)
- && PRECEDENCE[self.right.operator] == PRECEDENCE[self.operator]) {
+ && (self.operator != "+"
+ || self.right.left.is_boolean(compressor)
+ || self.right.left.is_number(compressor))) {
self = make_node(AST_Binary, self, {
operator: align(self.operator, self.right.operator),
left: make_node(AST_Binary, self.left, {