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);
|
self.expression = best_of_expression(expression, self.expression);
|
||||||
}
|
}
|
||||||
if (compressor.option("dead_code")) {
|
if (compressor.option("dead_code")) {
|
||||||
var blocks = Object.create(null);
|
var prev_block;
|
||||||
var decl = [];
|
var decl = [];
|
||||||
var body = [];
|
var body = [];
|
||||||
var default_branch;
|
var default_branch;
|
||||||
|
|
@ -2544,22 +2544,16 @@ merge(Compressor.prototype, {
|
||||||
}
|
}
|
||||||
var case_side_effects = branch instanceof AST_Case && branch.expression.has_side_effects(compressor);
|
var case_side_effects = branch instanceof AST_Case && branch.expression.has_side_effects(compressor);
|
||||||
if (aborts(branch)) {
|
if (aborts(branch)) {
|
||||||
var key = make_node(AST_BlockStatement, branch, branch).print_to_string();
|
var block = make_node(AST_BlockStatement, branch, branch).print_to_string();
|
||||||
var block;
|
if (!fallthrough && prev_block === block) body[body.length - 1].body = [];
|
||||||
if (!fallthrough && (block = blocks[key])) {
|
body.push(branch);
|
||||||
var insert = body.indexOf(block) + 1;
|
prev_block = block;
|
||||||
if (insert == body.length || !case_side_effects) {
|
|
||||||
block.body = [];
|
|
||||||
body.splice(insert, 0, branch);
|
|
||||||
} else body.push(branch);
|
|
||||||
} else body.push(branch);
|
|
||||||
fallthrough = false;
|
fallthrough = false;
|
||||||
} else {
|
} else {
|
||||||
body.push(branch);
|
body.push(branch);
|
||||||
|
prev_block = null;
|
||||||
fallthrough = true;
|
fallthrough = true;
|
||||||
}
|
}
|
||||||
if (case_side_effects) blocks = Object.create(null);
|
|
||||||
if (!fallthrough) blocks[key] = branch;
|
|
||||||
}
|
}
|
||||||
for (; i < len && fallthrough; i++) {
|
for (; i < len && fallthrough; i++) {
|
||||||
branch = self.body[i];
|
branch = self.body[i];
|
||||||
|
|
|
||||||
|
|
@ -542,11 +542,11 @@ issue_1680_2: {
|
||||||
var a = 100, b = 10;
|
var a = 100, b = 10;
|
||||||
switch (b) {
|
switch (b) {
|
||||||
case a--:
|
case a--:
|
||||||
case a:
|
|
||||||
break;
|
break;
|
||||||
case b:
|
case b:
|
||||||
var c;
|
var c;
|
||||||
break;
|
break;
|
||||||
|
case a:
|
||||||
case a--:
|
case a--:
|
||||||
}
|
}
|
||||||
console.log(a, b);
|
console.log(a, b);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user