return x;
};
- var readOnlyPrefix = makePredicate("! ~ + - void typeof");
- function statement_to_expression(stat) {
- if (stat.body instanceof AST_UnaryPrefix && readOnlyPrefix(stat.body.operator)) {
- return stat.body.expression;
- } else {
- return stat.body;
- }
- }
-
function is_iife_call(node) {
if (node instanceof AST_Call && !(node instanceof AST_New)) {
return node.expression instanceof AST_Function || is_iife_call(node.expression);
};
statements.forEach(function(stat){
if (stat instanceof AST_SimpleStatement) {
- if (seqLength(seq) >= compressor.sequences_limit) {
- push_seq();
- }
- seq.push(seq.length > 0 ? statement_to_expression(stat) : stat.body);
+ if (seqLength(seq) >= compressor.sequences_limit) push_seq();
+ var body = stat.body;
+ if (seq.length > 0) body = body.drop_side_effect_free(compressor);
+ if (body) seq.push(body);
} else {
push_seq();
ret.push(stat);
stat.init = cons_seq(stat.init);
}
else if (!stat.init) {
- stat.init = statement_to_expression(prev);
+ stat.init = prev.body.drop_side_effect_free(compressor);
ret.pop();
}
} catch(ex) {
switch (this.operator) {
case "&&":
case "||":
+ if (right === this.right) return this;
var node = this.clone();
node.right = right;
return node;
return make_node(AST_SimpleStatement, self, {
body: make_node(AST_Conditional, self, {
condition : self.condition,
- consequent : statement_to_expression(self.body),
- alternative : statement_to_expression(self.alternative)
+ consequent : self.body.body,
+ alternative : self.alternative.body
})
}).optimize(compressor);
}
body: make_node(AST_Binary, self, {
operator : "||",
left : negated,
- right : statement_to_expression(self.body)
+ right : self.body.body
})
}).optimize(compressor);
return make_node(AST_SimpleStatement, self, {
body: make_node(AST_Binary, self, {
operator : "&&",
left : self.condition,
- right : statement_to_expression(self.body)
+ right : self.body.body
})
}).optimize(compressor);
}
if (self.body instanceof AST_EmptyStatement
- && self.alternative
&& self.alternative instanceof AST_SimpleStatement) {
return make_node(AST_SimpleStatement, self, {
body: make_node(AST_Binary, self, {
operator : "||",
left : self.condition,
- right : statement_to_expression(self.alternative)
+ right : self.alternative.body
})
}).optimize(compressor);
}