eliminate redundant directives in the same scope

This commit is contained in:
Mihai Bazon
2012-10-08 12:53:17 +03:00
parent 80a18fe2fa
commit 093a9031dc

View File

@@ -194,12 +194,20 @@ merge(Compressor.prototype, {
return statements; return statements;
function eliminate_spurious_blocks(statements) { function eliminate_spurious_blocks(statements) {
var seen_dirs = [];
return statements.reduce(function(a, stat){ return statements.reduce(function(a, stat){
if (stat instanceof AST_BlockStatement) { if (stat instanceof AST_BlockStatement) {
CHANGED = true; CHANGED = true;
a.push.apply(a, eliminate_spurious_blocks(stat.body)); a.push.apply(a, eliminate_spurious_blocks(stat.body));
} else if (stat instanceof AST_EmptyStatement) { } else if (stat instanceof AST_EmptyStatement) {
CHANGED = true; CHANGED = true;
} else if (stat instanceof AST_Directive) {
if (seen_dirs.indexOf(stat.value) < 0) {
a.push(stat);
seen_dirs.push(stat.value);
} else {
CHANGED = true;
}
} else { } else {
a.push(stat); a.push(stat);
} }