diff --git a/lib/compress.js b/lib/compress.js index 1d009726..fd24f333 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -2515,7 +2515,7 @@ merge(Compressor.prototype, { self.expression = best_of_expression(expression, self.expression); } if (compressor.option("dead_code")) { - var blocks = Object.create(null); + var prev_block; var decl = []; var body = []; var default_branch; @@ -2544,22 +2544,16 @@ merge(Compressor.prototype, { } var case_side_effects = branch instanceof AST_Case && branch.expression.has_side_effects(compressor); if (aborts(branch)) { - var key = make_node(AST_BlockStatement, branch, branch).print_to_string(); - var block; - if (!fallthrough && (block = blocks[key])) { - var insert = body.indexOf(block) + 1; - if (insert == body.length || !case_side_effects) { - block.body = []; - body.splice(insert, 0, branch); - } else body.push(branch); - } else body.push(branch); + var block = make_node(AST_BlockStatement, branch, branch).print_to_string(); + if (!fallthrough && prev_block === block) body[body.length - 1].body = []; + body.push(branch); + prev_block = block; fallthrough = false; } else { body.push(branch); + prev_block = null; fallthrough = true; } - if (case_side_effects) blocks = Object.create(null); - if (!fallthrough) blocks[key] = branch; } for (; i < len && fallthrough; i++) { branch = self.body[i]; diff --git a/test/compress/switch.js b/test/compress/switch.js index 546e1613..2025d91b 100644 --- a/test/compress/switch.js +++ b/test/compress/switch.js @@ -542,11 +542,11 @@ issue_1680_2: { var a = 100, b = 10; switch (b) { case a--: - case a: break; case b: var c; break; + case a: case a--: } console.log(a, b);