remove paranthesis for -(x*y) (#1732)

This commit is contained in:
Alex Lam S.L
2017-03-30 16:09:00 +08:00
committed by GitHub
parent 7bea38a05d
commit 7cb1adf455
2 changed files with 41 additions and 0 deletions

View File

@@ -3034,6 +3034,13 @@ merge(Compressor.prototype, {
})).optimize(compressor); })).optimize(compressor);
} }
} }
if (e instanceof AST_Binary
&& (self.operator == "+" || self.operator == "-")
&& (e.operator == "*" || e.operator == "/" || e.operator == "%")) {
self.expression = e.left;
e.left = self;
return e.optimize(compressor);
}
// avoids infinite recursion of numerals // avoids infinite recursion of numerals
if (self.operator != "-" if (self.operator != "-"
|| !(self.expression instanceof AST_Number || !(self.expression instanceof AST_Number

View File

@@ -168,3 +168,37 @@ issue_1710: {
} }
expect_stdout: true expect_stdout: true
} }
unary_binary_parenthesis: {
input: {
var v = [ 0, 1, NaN, Infinity, null, undefined, true, false, "", "foo", /foo/ ];
v.forEach(function(x) {
v.forEach(function(y) {
console.log(
+(x*y),
+(x/y),
+(x%y),
-(x*y),
-(x/y),
-(x%y)
);
});
});
}
expect: {
var v = [ 0, 1, 0/0, 1/0, null, void 0, true, false, "", "foo", /foo/ ];
v.forEach(function(x) {
v.forEach(function(y) {
console.log(
+x*y,
+x/y,
+x%y,
-x*y,
-x/y,
-x%y
);
});
});
}
expect_stdout: true
}