From 751756ddffdbdf8061b4b73ac6848c0a1f5e61b7 Mon Sep 17 00:00:00 2001 From: Ryan Kelly Date: Tue, 20 May 2014 15:17:18 +1000 Subject: Fix elimination of conditional expressions in registerizeHarder. Previously, attempts to eliminate a side-effect-free conditional expression would corrupt internal block state, because the sub-nodes belong to a different block than the one containing the expression. This fixes the problem by not splitting side-effect free conditionals across multiple blocks. --- tools/js-optimizer.js | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'tools/js-optimizer.js') diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 088c4f0f..2004efda 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -2237,18 +2237,30 @@ function registerizeHarder(ast) { break; case 'conditional': isInExpr++; - buildFlowGraph(node[1]); - var jEnter = markJunction(); - var jExit = addJunction(); - if (node[2]) { - buildFlowGraph(node[2]); - } - joinJunction(jExit); - setJunction(jEnter); - if (node[3]) { - buildFlowGraph(node[3]); + // If the conditional has no side-effects, we can treat it as a single + // block, which might open up opportunities to remove it entirely. + if (!hasSideEffects(node)) { + buildFlowGraph(node[1]); + if (node[2]) { + buildFlowGraph(node[2]); + } + if (node[3]) { + buildFlowGraph(node[3]); + } + } else { + buildFlowGraph(node[1]); + var jEnter = markJunction(); + var jExit = addJunction(); + if (node[2]) { + buildFlowGraph(node[2]); + } + joinJunction(jExit); + setJunction(jEnter); + if (node[3]) { + buildFlowGraph(node[3]); + } + joinJunction(jExit); } - joinJunction(jExit); isInExpr--; break; case 'while': -- cgit v1.2.3-70-g09d2