drop unused function
This commit is contained in:
118
lib/compress.js
118
lib/compress.js
@@ -317,124 +317,6 @@ function Compressor(options, false_by_default) {
|
||||
return ret;
|
||||
};
|
||||
|
||||
/// XXX: this function is UGLY and kinda wrong.
|
||||
/// I think it would be cleaner if it operates backwards.
|
||||
function handle_if_return_2(statements, compressor) {
|
||||
var self = compressor.self();
|
||||
var in_lambda = self instanceof AST_Lambda;
|
||||
var last = statements.length - 1;
|
||||
return MAP(statements, function(stat, i){
|
||||
if (stat instanceof AST_If
|
||||
&& stat.body instanceof AST_Continue
|
||||
&& !stat.alternative
|
||||
&& self === stat.body.target()) {
|
||||
CHANGED = true;
|
||||
if (i < last) {
|
||||
var rest = statements.slice(i + 1);
|
||||
var cond = stat.condition;
|
||||
while (rest[0] instanceof AST_If
|
||||
&& rest[0].body instanceof AST_Continue
|
||||
&& self === rest[0].body.target()
|
||||
&& !rest[0].alternative) {
|
||||
cond = make_node(AST_Binary, rest[0], {
|
||||
operator: "||",
|
||||
left: cond,
|
||||
right: rest[0].condition
|
||||
});
|
||||
rest.shift();
|
||||
}
|
||||
return MAP.last(make_node(AST_If, stat, {
|
||||
condition: cond.negate(compressor),
|
||||
body: make_node(AST_BlockStatement, stat, {
|
||||
body: rest
|
||||
}).optimize(compressor)
|
||||
}).optimize(compressor))
|
||||
} else {
|
||||
return make_node(AST_SimpleStatement, stat, {
|
||||
body: stat.condition
|
||||
}).optimize(compressor);
|
||||
}
|
||||
}
|
||||
if (stat instanceof AST_If
|
||||
&& stat.body instanceof AST_Return
|
||||
&& !stat.alternative
|
||||
&& in_lambda) {
|
||||
if (!stat.body.value) {
|
||||
CHANGED = true;
|
||||
if (i < last) {
|
||||
var rest = statements.slice(i + 1);
|
||||
var cond = stat.condition;
|
||||
while (rest[0] instanceof AST_If
|
||||
&& rest[0].body instanceof AST_Return
|
||||
&& !rest[0].body.value
|
||||
&& !rest[0].alternative) {
|
||||
cond = make_node(AST_Binary, rest[0], {
|
||||
operator: "||",
|
||||
left: cond,
|
||||
right: rest[0].condition
|
||||
});
|
||||
rest.shift();
|
||||
}
|
||||
return MAP.last(make_node(AST_If, stat, {
|
||||
condition: cond.negate(compressor),
|
||||
body: make_node(AST_BlockStatement, stat, {
|
||||
body: rest
|
||||
}).optimize(compressor)
|
||||
}).optimize(compressor));
|
||||
} else {
|
||||
return make_node(AST_SimpleStatement, stat, {
|
||||
body: stat.condition
|
||||
}).optimize(compressor);
|
||||
}
|
||||
} else if (i == last && last > 0
|
||||
&& statements[last - 1] instanceof AST_If
|
||||
&& statements[last - 1].body instanceof AST_Return
|
||||
&& !statements[last - 1].alternative) {
|
||||
CHANGED = true;
|
||||
return MAP.splice([ stat, make_node(AST_Return, stat, {
|
||||
value: make_node(AST_Undefined, stat).optimize(compressor)
|
||||
}).optimize(compressor)]);
|
||||
}
|
||||
}
|
||||
if (stat instanceof AST_If
|
||||
&& stat.body instanceof AST_Exit
|
||||
&& stat.body.value
|
||||
&& !stat.alternative
|
||||
&& i < last
|
||||
&& statements[i + 1].TYPE == stat.body.TYPE
|
||||
&& statements[i + 1].value) {
|
||||
CHANGED = true;
|
||||
return MAP.last(make_node(AST_If, stat, {
|
||||
condition: stat.condition,
|
||||
body: stat.body,
|
||||
alternative: statements[i + 1]
|
||||
}).optimize(compressor));
|
||||
}
|
||||
if (stat instanceof AST_If
|
||||
&& stat.alternative instanceof AST_Exit) {
|
||||
CHANGED = true;
|
||||
return MAP.last(MAP.splice([
|
||||
// 1. negate IF and put the exit in the consequent
|
||||
make_node(AST_If, stat, {
|
||||
condition: stat.condition.negate(compressor),
|
||||
body: stat.alternative
|
||||
}),
|
||||
// 2. the IF body can now go outside the if
|
||||
stat.body
|
||||
// and 3. add the rest of the statements
|
||||
].concat(statements.slice(i + 1))));
|
||||
return MAP.last(make_node(AST_If, stat, {
|
||||
condition: stat.condition.negate(compressor),
|
||||
body: stat.alternative,
|
||||
alternative: make_node(AST_BlockStatement, stat.body, {
|
||||
body: [ stat.body ].concat(statements.slice(i + 1))
|
||||
})
|
||||
}).optimize(compressor));
|
||||
}
|
||||
return stat;
|
||||
});
|
||||
};
|
||||
|
||||
function eliminate_dead_code(statements, compressor) {
|
||||
var has_quit = false;
|
||||
return statements.reduce(function(a, stat){
|
||||
|
||||
Reference in New Issue
Block a user