diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-10-29 17:06:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-29 17:06:57 +0800 |
commit | 22a09ea7c599e2618ee933ed56ca165a3d2d663b (patch) | |
tree | 60d3dc3d12a4746499ac3a232b89f4e3025f946b /lib | |
parent | bad664c6322538f1a5eec7f76dc44f81fa05c9e0 (diff) | |
download | tracifyjs-22a09ea7c599e2618ee933ed56ca165a3d2d663b.tar.gz tracifyjs-22a09ea7c599e2618ee933ed56ca165a3d2d663b.zip |
fix corner case in `unsafe_math` (#3548)
fixes #3547
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/lib/compress.js b/lib/compress.js index 3058b678..d37108d1 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -6024,9 +6024,12 @@ merge(Compressor.prototype, { if (self.right instanceof AST_Constant && self.left instanceof AST_Binary && self.left.operator != "%" - && PRECEDENCE[self.left.operator] == PRECEDENCE[self.operator]) { + && PRECEDENCE[self.left.operator] == PRECEDENCE[self.operator] + && self.left.is_number(compressor)) { if (self.left.left instanceof AST_Constant - && (self.left.operator != "+" || self.left.right.is_number(compressor))) { + && (self.operator != "+" + || self.left.left.is_boolean(compressor) + || self.left.left.is_number(compressor))) { self = make_node(AST_Binary, self, { operator: self.left.operator, left: make_node(AST_Binary, self.left, { @@ -6038,19 +6041,23 @@ merge(Compressor.prototype, { }), right: self.left.right }); - } else if (self.left.right instanceof AST_Constant - && (self.left.operator != "+" || self.left.left.is_number(compressor))) { - self = make_node(AST_Binary, self, { - operator: self.left.operator, - left: self.left.left, - right: make_node(AST_Binary, self.left, { - operator: align(self.left.operator, self.operator), - left: self.left.right, - right: self.right, - start: self.left.right.start, - end: self.right.end - }) - }); + } else if (self.left.right instanceof AST_Constant) { + var op = align(self.left.operator, self.operator); + if (op != "+" + || self.left.right.is_boolean(compressor) + || self.left.right.is_number(compressor)) { + self = make_node(AST_Binary, self, { + operator: self.left.operator, + left: self.left.left, + right: make_node(AST_Binary, self.left, { + operator: op, + left: self.left.right, + right: self.right, + start: self.left.right.start, + end: self.right.end + }) + }); + } } } break; |