// no need to descend these node types
return node;
}
- else if (node instanceof AST_Switch && node === self) {
+ else if (node === self) {
node = node.clone();
descend(node, this);
return ruined ? node : make_node(AST_BlockStatement, node, {
- body: node.body.reduce(function(a, branch){
- return a.concat(branch.body);
- }, [])
- }).transform(compressor);
+ body: node.body.map(function(stat) {
+ return stat instanceof AST_SwitchBranch ? make_node(AST_BlockStatement, stat, stat) : stat;
+ })
+ }).optimize(compressor);
}
else if (node instanceof AST_If || node instanceof AST_Try) {
var save = in_if;
}
if (in_block) return node;
stopped = true;
- return in_list ? MAP.skip : make_node(AST_EmptyStatement, node);
+ return skip(node);
}
else if (node instanceof AST_SwitchBranch && this.parent() === self) {
- if (stopped) return MAP.skip;
+ if (stopped) return skip(node);
if (node instanceof AST_Case) {
var exp = node.expression.evaluate(compressor);
if (exp === node.expression) {
if (exp === value || started) {
started = true;
if (aborts(node)) stopped = true;
- descend(node, this);
- return node;
- }
- return MAP.skip;
+ } else return skip(node);
}
- descend(node, this);
- return node;
+ }
+
+ function skip(node) {
+ var a = [];
+ extract_declarations_from_unreachable_code(compressor, node, a);
+ return in_list ? MAP.splice(a) : make_node(AST_BlockStatement, node, {
+ body: a
+ });
}
});
- tt.stack = compressor.stack.slice(); // so that's able to see parent nodes
+ // allow transform() to view the whole AST
+ tt.stack = compressor.stack.slice(0, -1);
self = self.transform(tt);
} catch(ex) {
if (ex !== self) throw ex;