de-duplicate trailing cases only
avoid all potential side-effects
This commit is contained in:
parent
4291ecc77c
commit
74d2f03dc6
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user