diff --git a/lib/compress.js b/lib/compress.js index 886a4b5b..70a70465 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3074,8 +3074,12 @@ merge(Compressor.prototype, { def(AST_Statement, return_null); def(AST_Jump, return_this); function block_aborts(){ - var n = this.body.length; - return n > 0 && aborts(this.body[n - 1]); + for (var i = 0; i < this.body.length; i++) { + if (aborts(this.body[i])) { + return this.body[i]; + } + } + return null; }; def(AST_Import, function(){ return null; }); def(AST_BlockStatement, block_aborts); diff --git a/test/compress/conditionals.js b/test/compress/conditionals.js index e37c5556..2754ffba 100644 --- a/test/compress/conditionals.js +++ b/test/compress/conditionals.js @@ -1204,6 +1204,45 @@ issue_2560: { ] } +issue_2994: { + options = { + conditionals: true, + if_return: true + } + input: { + function f() { + if (condition1) { + if (condition2) { + return aValue; + } else { + const variable1 = 'something'; + if (condition3) { + const variable2 = 'else'; + return anotherValue; + } else { + return undefined; + } + } + } + } + } + expect: { + function f() { + if (condition1) { + if (condition2) return aValue; + { + const variable1 = 'something'; + if (condition3) { + const variable2 = 'else'; + return anotherValue; + } + return; + } + } + } + } +} + hoist_decl: { options = { conditionals: true,