enhance if_return (#5330)
This commit is contained in:
@@ -3294,7 +3294,8 @@ Compressor.prototype.compress = function(node) {
|
||||
function handle_if_return(statements, compressor) {
|
||||
var changed = false;
|
||||
var parent = compressor.parent();
|
||||
var in_iife = in_lambda && parent && parent.TYPE == "Call";
|
||||
var self = compressor.self();
|
||||
var in_iife = in_lambda && parent && parent.TYPE == "Call" && parent.expression === self;
|
||||
var chain_if_returns = in_lambda && compressor.option("conditionals") && compressor.option("sequences");
|
||||
var multiple_if_returns = has_multiple_if_returns(statements);
|
||||
for (var i = statements.length; --i >= 0;) {
|
||||
@@ -3371,15 +3372,11 @@ Compressor.prototype.compress = function(node) {
|
||||
|
||||
if (compressor.option("typeofs")) {
|
||||
if (ab && !alt) {
|
||||
var stats = make_node(AST_BlockStatement, compressor.self(), {
|
||||
body: statements.slice(i + 1),
|
||||
});
|
||||
var stats = make_node(AST_BlockStatement, self, { body: statements.slice(i + 1) });
|
||||
mark_locally_defined(stat.condition, null, stats);
|
||||
}
|
||||
if (!ab && alt) {
|
||||
var stats = make_node(AST_BlockStatement, compressor.self(), {
|
||||
body: statements.slice(i + 1),
|
||||
});
|
||||
var stats = make_node(AST_BlockStatement, self, { body: statements.slice(i + 1) });
|
||||
mark_locally_defined(stat.condition, stats);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,7 +395,31 @@ if_var_return_2: {
|
||||
}
|
||||
}
|
||||
|
||||
if_var_return_3: {
|
||||
if_var_retrn_3: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
sequences: true,
|
||||
}
|
||||
input: {
|
||||
f(function() {
|
||||
var a = w();
|
||||
if (x())
|
||||
return y(a);
|
||||
z();
|
||||
});
|
||||
}
|
||||
expect: {
|
||||
f(function() {
|
||||
var a = w();
|
||||
if (x())
|
||||
return y(a);
|
||||
z();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if_var_return_4: {
|
||||
options = {
|
||||
conditionals: true,
|
||||
if_return: true,
|
||||
|
||||
Reference in New Issue
Block a user