aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-01-08 10:28:10 +0800
committerGitHub <noreply@github.com>2020-01-08 10:28:10 +0800
commit14c35739ddb1c0b181d8c54566171f217014b563 (patch)
tree4c24265ebc3e76fb44c7611c5d1204e9d224ef35
parentf5ceff6e4b94a032078b0730f91662ee62758eb4 (diff)
downloadtracifyjs-14c35739ddb1c0b181d8c54566171f217014b563.tar.gz
tracifyjs-14c35739ddb1c0b181d8c54566171f217014b563.zip
fix corner case in `unsafe_math` (#3677)
fixes #3676
-rw-r--r--lib/compress.js4
-rw-r--r--test/compress/numbers.js32
2 files changed, 35 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index f5d60ffc..c596de3e 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -6529,7 +6529,9 @@ merge(Compressor.prototype, {
&& self.right.is_number(compressor)
&& (self.operator != "+"
|| self.right.left.is_boolean(compressor)
- || self.right.left.is_number(compressor))) {
+ || self.right.left.is_number(compressor))
+ && (self.right.left.is_constant_expression()
+ || !self.right.right.has_side_effects(compressor))) {
self = make_node(AST_Binary, self, {
operator: align(self.operator, self.right.operator),
left: make_node(AST_Binary, self.left, {
diff --git a/test/compress/numbers.js b/test/compress/numbers.js
index f49996a4..c40ca09d 100644
--- a/test/compress/numbers.js
+++ b/test/compress/numbers.js
@@ -1135,3 +1135,35 @@ issue_3655: {
"0",
]
}
+
+issue_3676_1: {
+ options = {
+ evaluate: true,
+ unsafe_math: true,
+ }
+ input: {
+ var a = [];
+ console.log(false - (a - (a[1] = 42)));
+ }
+ expect: {
+ var a = [];
+ console.log(false - (a - (a[1] = 42)));
+ }
+ expect_stdout: "NaN"
+}
+
+issue_3676_2: {
+ options = {
+ evaluate: true,
+ unsafe_math: true,
+ }
+ input: {
+ var a;
+ console.log(false - ((a = []) - (a[1] = 42)));
+ }
+ expect: {
+ var a;
+ console.log(false - ((a = []) - (a[1] = 42)));
+ }
+ expect_stdout: "NaN"
+}