aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-03-26 16:52:38 +0800
committerGitHub <noreply@github.com>2017-03-26 16:52:38 +0800
commit3276740779077f2ee7b686c4aa7f1bd46fbc1c66 (patch)
tree2c17715ca1e6e44158b68f7381d1c9e903bb851b /lib
parent5509e51098274b28b8574246011767ba0be66edd (diff)
downloadtracifyjs-3276740779077f2ee7b686c4aa7f1bd46fbc1c66.tar.gz
tracifyjs-3276740779077f2ee7b686c4aa7f1bd46fbc1c66.zip
fallthrough should not execute case expression (#1683)
- de-duplicate trailing cases only, avoid all potential side-effects - enable switch statement fuzzing fixes #1680
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js24
1 files changed, 7 insertions, 17 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 70bbb7fc..8467f96c 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;
@@ -2542,31 +2542,21 @@ merge(Compressor.prototype, {
continue;
}
}
+ 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])) {
- block.body = [];
- body.splice(body.indexOf(block) + 1, 0, 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 (branch instanceof AST_Case && branch.expression.has_side_effects(compressor))
- blocks = Object.create(null);
- if (!fallthrough) blocks[key] = branch;
}
for (; i < len && fallthrough; i++) {
branch = self.body[i];
- if (branch instanceof AST_Case) {
- exact_match.body.push(make_node(AST_SimpleStatement, branch.expression, {
- body: branch.expression
- }));
- }
exact_match.body = exact_match.body.concat(branch.body);
fallthrough = !aborts(exact_match);
}