From 7e575e9d7f40876373f073213126b729553c4d89 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 23 Dec 2020 20:08:57 +0000 Subject: [PATCH] fix corner case in `if_return` (#4439) fixes #4438 --- lib/compress.js | 2 +- test/compress/let.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index 38342326..c397a605 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -2669,7 +2669,7 @@ merge(Compressor.prototype, { block = last.body; } block.pop(); - if (ab.value) body.push(make_node(AST_SimpleStatement, ab.value, { + if (ab.value) block.push(make_node(AST_SimpleStatement, ab.value, { body: ab.value.expression })); return body; diff --git a/test/compress/let.js b/test/compress/let.js index fc323320..59b89023 100644 --- a/test/compress/let.js +++ b/test/compress/let.js @@ -1228,3 +1228,35 @@ issue_1753_toplevel: { expect_stdout: "0" node_version: ">=4" } + +issue_4438: { + options = { + if_return: true, + } + input: { + "use strict"; + function f() { + if (console) { + { + let a = console.log; + return void a("PASS"); + } + } + } + f(); + } + expect: { + "use strict"; + function f() { + if (!console) + ; + else { + let a = console.log; + a("PASS"); + } + } + f(); + } + expect_stdout: "PASS" + node_version: ">=4" +} -- 2.34.1