improve exceptional flow compression by collapse_vars (#2880)

This commit is contained in:
Alex Lam S.L
2018-02-04 04:18:22 +08:00
committed by GitHub
parent 78a44d5ab0
commit 3026bd8975
2 changed files with 9 additions and 22 deletions

View File

@@ -1408,22 +1408,15 @@ merge(Compressor.prototype, {
} }
function side_effects_external(node, lhs) { function side_effects_external(node, lhs) {
if (node instanceof AST_Assign) { if (node instanceof AST_Assign) return side_effects_external(node.left, true);
return side_effects_external(node.left, true)
|| side_effects_external(node.right);
}
if (node instanceof AST_Definitions) return false;
if (node instanceof AST_Unary) return side_effects_external(node.expression, true); if (node instanceof AST_Unary) return side_effects_external(node.expression, true);
if (node instanceof AST_VarDef) return node.value && side_effects_external(node.value); if (node instanceof AST_VarDef) return node.value && side_effects_external(node.value);
if (lhs) { if (lhs) {
if (node instanceof AST_Dot) return side_effects_external(node.expression, true); if (node instanceof AST_Dot) return side_effects_external(node.expression, true);
if (node instanceof AST_Sub) { if (node instanceof AST_Sub) return side_effects_external(node.expression, true);
return side_effects_external(node.expression, true)
|| side_effects_external(node.property);
}
if (node instanceof AST_SymbolRef) return node.definition().scope !== scope; if (node instanceof AST_SymbolRef) return node.definition().scope !== scope;
} }
return node.has_side_effects(compressor); return false;
} }
} }

View File

@@ -4281,19 +4281,16 @@ cond_branch_1: {
} }
expect: { expect: {
function f1(b, c) { function f1(b, c) {
var log = console.log;
if (b) b++; if (b) b++;
log(++c, b); (0, console.log)(++c, b);
} }
function f2(b, c) { function f2(b, c) {
var log = console.log;
b && b++, b && b++,
log(++c, b); (0, console.log)(++c, b);
} }
function f3(b, c) { function f3(b, c) {
var log = console.log;
b ? b++ : b--, b ? b++ : b--,
log(++c, b); (0, console.log)(++c, b);
} }
f1(1, 2), f1(1, 2),
f2(3, 4), f2(3, 4),
@@ -4337,22 +4334,19 @@ cond_branch_2: {
} }
expect: { expect: {
function f1(b, c) { function f1(b, c) {
var log = console.log;
var a = ++c; var a = ++c;
if (b) b += a; if (b) b += a;
log(a, b); (0, console.log)(a, b);
} }
function f2(b, c) { function f2(b, c) {
var log = console.log;
var a = ++c; var a = ++c;
b && (b += a), b && (b += a),
log(a, b); (0, console.log)(a, b);
} }
function f3(b, c) { function f3(b, c) {
var log = console.log;
var a = ++c; var a = ++c;
b ? b += a : b--, b ? b += a : b--,
log(a, b); (0, console.log)(a, b);
} }
f1(1, 2), f1(1, 2),
f2(3, 4), f2(3, 4),