diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-11-18 13:44:13 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-18 13:44:13 +0800 |
commit | 644f65feca92d03076c57a6a078dc9c35a82fadb (patch) | |
tree | 3e0eebe2689d57c72662952040b6e91ec44590f2 /lib | |
parent | 8504a4ea0eddeb759f6f762f4ee46e5dde5f8e07 (diff) | |
download | tracifyjs-644f65feca92d03076c57a6a078dc9c35a82fadb.tar.gz tracifyjs-644f65feca92d03076c57a6a078dc9c35a82fadb.zip |
fix corner case in `unsafe_math` (#3594)
fixes #3593
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 60 |
1 files changed, 29 insertions, 31 deletions
diff --git a/lib/compress.js b/lib/compress.js index 45db019b..b7a73430 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -6191,38 +6191,12 @@ merge(Compressor.prototype, { && self.left.operator != "%" && PRECEDENCE[self.left.operator] == PRECEDENCE[self.operator] && self.left.is_number(compressor)) { - if (self.left.left instanceof AST_Constant - && (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, { - operator: self.operator, - left: self.left.left, - right: self.right, - start: self.left.left.start, - end: self.right.end - }), - right: self.left.right - }); + 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); } 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 - }) - }); - } + var rhs = make_binary(self.left, align(self.left.operator, self.operator), self.left.right, self.right, self.left.right.start, self.right.end); + self = make_binary(self, self.left.operator, self.left.left, rhs); } } break; @@ -6304,6 +6278,30 @@ merge(Compressor.prototype, { } } + function make_binary(orig, op, left, right, start, end) { + if (op == "+") { + if (!left.is_boolean(compressor) && !left.is_number(compressor)) { + left = make_node(AST_UnaryPrefix, left, { + operator: "+", + expression: left + }); + } + if (!right.is_boolean(compressor) && !right.is_number(compressor)) { + right = make_node(AST_UnaryPrefix, right, { + operator: "+", + expression: right + }); + } + } + return make_node(AST_Binary, orig, { + operator: op, + left: left, + right: right, + start: start, + end: end + }); + } + function fuzzy_eval(node) { if (node.truthy) return true; if (node.falsy) return false; |