aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-03-27 02:32:46 +0800
committerGitHub <noreply@github.com>2017-03-27 02:32:46 +0800
commitf5952933a00bac8c9d794d5b0e3d5f8d6173c4a9 (patch)
tree167c83c5e7084d722738be5b1dc47bc7e15d7fe2 /lib
parentf001e4cb9d5bfe56e25db552bb7ab0951a142a99 (diff)
downloadtracifyjs-f5952933a00bac8c9d794d5b0e3d5f8d6173c4a9.tar.gz
tracifyjs-f5952933a00bac8c9d794d5b0e3d5f8d6173c4a9.zip
preserve side effects in switch expression (#1694)
fixes #1690
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js15
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 8350ba25..9ed368c7 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2560,10 +2560,9 @@ merge(Compressor.prototype, {
fallthrough = !aborts(exact_match);
}
while (i < len) extract_declarations_from_unreachable_code(compressor, self.body[i++], decl);
- if (body.length == 0) return make_node(AST_BlockStatement, self, {
- body: decl
- }).optimize(compressor);
- body[0].body = decl.concat(body[0].body);
+ if (body.length > 0) {
+ body[0].body = decl.concat(body[0].body);
+ }
self.body = body;
}
while (branch = self.body[self.body.length - 1]) {
@@ -2575,9 +2574,11 @@ merge(Compressor.prototype, {
&& branch.expression.has_side_effects(compressor)) break;
self.body.pop();
}
- if (compressor.option("conditionals") && self.body.length == 0) {
- return make_node(AST_SimpleStatement, self, {
- body: self.expression
+ if (decl && self.body.length == 0) {
+ return make_node(AST_BlockStatement, self, {
+ body: decl.concat(make_node(AST_SimpleStatement, self.expression, {
+ body: self.expression
+ }))
}).optimize(compressor);
}
if (body && body.length == 1 && (body[0] === exact_match || body[0] === default_branch)) {