general improvements around AST_ForIn (#2796)

- compress using `collapse_vars`
- remove unused `name`
- simplify `loop_body`
This commit is contained in:
Alex Lam S.L
2018-01-16 17:03:12 +08:00
committed by GitHub
parent 424173d311
commit b4aef753e7
4 changed files with 35 additions and 7 deletions

View File

@@ -847,9 +847,8 @@ merge(Compressor.prototype, {
};
function loop_body(x) {
if (x instanceof AST_Switch) return x;
if (x instanceof AST_For || x instanceof AST_ForIn || x instanceof AST_DWLoop) {
return (x.body instanceof AST_BlockStatement ? x.body : x);
if (x instanceof AST_IterationStatement) {
return x.body instanceof AST_BlockStatement ? x.body : x;
}
return x;
};
@@ -1193,6 +1192,11 @@ merge(Compressor.prototype, {
if (!(expr.body instanceof AST_Block)) {
extract_candidates(expr.body);
}
} else if (expr instanceof AST_ForIn) {
extract_candidates(expr.object);
if (!(expr.body instanceof AST_Block)) {
extract_candidates(expr.body);
}
} else if (expr instanceof AST_If) {
extract_candidates(expr.condition);
if (!(expr.body instanceof AST_Block)) {