diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-10-12 04:09:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-12 11:09:26 +0800 |
commit | 74ff6ce261548289c96f7d907a3605640e20e9d1 (patch) | |
tree | 380a4799982a9f5ee3af81f499ab81fae5861d93 | |
parent | b1b8898e7c3ced21c601b3a8d618aff2fd468d63 (diff) | |
download | tracifyjs-74ff6ce261548289c96f7d907a3605640e20e9d1.tar.gz tracifyjs-74ff6ce261548289c96f7d907a3605640e20e9d1.zip |
fix corner case in `dead_code` (#4194)
fixes #4193
-rw-r--r-- | lib/compress.js | 9 | ||||
-rw-r--r-- | 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 +} |