Skip to content

Commit

Permalink
fix corner case in unsafe_math (#3677)
Browse files Browse the repository at this point in the history
fixes #3676
  • Loading branch information
alexlamsl committed Jan 8, 2020
1 parent f5ceff6 commit 14c3573
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/compress.js
Expand Up @@ -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, {
Expand Down
32 changes: 32 additions & 0 deletions test/compress/numbers.js
Expand Up @@ -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"
}

0 comments on commit 14c3573

Please sign in to comment.