From 74ff6ce261548289c96f7d907a3605640e20e9d1 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 12 Oct 2020 04:09:26 +0100 Subject: [PATCH] fix corner case in `dead_code` (#4194) fixes #4193 --- lib/compress.js | 9 ++++++--- test/compress/const.js | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 7d5e0221..c4012031 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -6571,14 +6571,17 @@ merge(Compressor.prototype, { }); }); } - [].unshift.apply(body, self.body); - if (self.bfinally) [].push.apply(body, self.bfinally.body); + body.unshift(make_node(AST_BlockStatement, self, self).optimize(compressor)); + if (self.bfinally) { + body.push(make_node(AST_BlockStatement, self.bfinally, self.bfinally).optimize(compressor)); + } return make_node(AST_BlockStatement, self, { body: body }).optimize(compressor); } if (self.bfinally && has_declarations_only(self.bfinally)) { - var body = self.body.concat(self.bfinally.body); + var body = make_node(AST_BlockStatement, self.bfinally, self.bfinally).optimize(compressor); + body = self.body.concat(body); if (!self.bcatch) return make_node(AST_BlockStatement, self, { body: body }).optimize(compressor); diff --git a/test/compress/const.js b/test/compress/const.js index bc37e144..f09dc56f 100644 --- a/test/compress/const.js +++ b/test/compress/const.js @@ -725,3 +725,25 @@ issue_4191_2: { } expect_stdout: "function undefined" } + +issue_4193: { + options = { + dead_code: true, + } + input: { + try {} catch (e) { + var a; + } finally { + const a = 0; + } + console.log(a); + } + expect: { + var a; + { + const a = 0; + } + console.log(a); + } + expect_stdout: true +} -- 2.34.1