return self;
});
- function trim_block(node) {
+ function trim_block(node, in_list) {
switch (node.body.length) {
case 0:
- return make_node(AST_EmptyStatement, node);
+ return in_list ? List.skip : make_node(AST_EmptyStatement, node);
case 1:
var stat = node.body[0];
if (!(stat instanceof AST_Const || stat instanceof AST_Let)) return stat;
return node;
}
}, function(node, in_list) {
- if (node instanceof AST_BlockStatement) switch (node.body.length) {
- case 0:
- return in_list ? List.skip : make_node(AST_EmptyStatement, node);
- case 1:
- var stat = node.body[0];
- if (!(stat instanceof AST_Const || stat instanceof AST_Let)) return stat;
+ if (node instanceof AST_BlockStatement) {
+ return trim_block(node, in_list);
} else if (node instanceof AST_For) {
// Certain combination of unused name + side effect leads to invalid AST:
// https://github.com/mishoo/UglifyJS/issues/44
var exprs = [];
for (var i = 0; i < stat.body.length; i++) {
var line = stat.body[i];
- if (line instanceof AST_Defun) {
+ if (is_defun(line)) {
defuns.push(line);
} else if (line instanceof AST_EmptyStatement) {
continue;
}
return exprs;
}
- if (stat instanceof AST_Defun) {
+ if (is_defun(stat)) {
defuns.push(stat);
return [];
}