return self;
});
+ var SIGN_OPS = makePredicate("+ -");
+ var MULTIPLICATIVE_OPS = makePredicate("* / %");
OPT(AST_UnaryPrefix, function(self, compressor) {
var e = self.expression;
if (compressor.option("evaluate")
])).optimize(compressor);
}
}
- if (self.operator == "-" && e instanceof AST_Infinity) {
- e = e.transform(compressor);
- }
- if (e instanceof AST_Binary
- && (self.operator == "+" || self.operator == "-")
- && (e.operator == "*" || e.operator == "/" || e.operator == "%")) {
+ if (self.operator == "-" && e instanceof AST_Infinity) e = e.transform(compressor);
+ if (compressor.option("evaluate")
+ && e instanceof AST_Binary
+ && SIGN_OPS[self.operator]
+ && MULTIPLICATIVE_OPS[e.operator]
+ && (e.left.is_constant() || !e.right.has_side_effects(compressor))) {
return make_node(AST_Binary, self, {
operator: e.operator,
left: make_node(AST_UnaryPrefix, e.left, {
if (self.right instanceof AST_Binary
&& self.operator == self.right.operator
&& (self.left.is_string(compressor) && self.right.is_string(compressor)
- || self.right.left.is_string(compressor) && !self.right.right.has_side_effects(compressor))) {
+ || self.right.left.is_string(compressor)
+ && (self.left.is_constant() || !self.right.right.has_side_effects(compressor)))) {
swap_chain();
}
}
return reachable;
}
- var ASSIGN_OPS = makePredicate("+ - / * % >> << >>> | ^ &");
+ var ASSIGN_OPS = makePredicate("+ - * / % >> << >>> | ^ &");
var ASSIGN_OPS_COMMUTATIVE = makePredicate("* | ^ &");
OPT(AST_Assign, function(self, compressor) {
if (compressor.option("dead_code")) {
}
unary_binary_parenthesis: {
+ options = {
+ evaluate: true,
+ }
input: {
var v = [ 0, 1, NaN, Infinity, null, undefined, true, false, "", "foo", /foo/ ];
v.forEach(function(x) {
"Infinity",
]
}
+
+issue_3695: {
+ options = {
+ evaluate: true,
+ }
+ input: {
+ var a = [];
+ console.log(+(a * (a[0] = false)));
+ }
+ expect: {
+ var a = [];
+ console.log(+(a * (a[0] = false)));
+ }
+ expect_stdout: "NaN"
+}