diff --git a/lib/compress.js b/lib/compress.js index c2a547eb..10ef1f34 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1953,7 +1953,7 @@ Compressor.prototype.compress = function(node) { function last_of(compressor, predicate) { var block = compressor.self(), level = 0; do { - if (block instanceof AST_Catch || block instanceof AST_Finally) { + if (block instanceof AST_Catch) { block = compressor.parent(level++); } else if (block instanceof AST_LabeledStatement) { block = block.body; @@ -1968,7 +1968,6 @@ Compressor.prototype.compress = function(node) { } while (stat && (block instanceof AST_BlockStatement || block instanceof AST_Catch - || block instanceof AST_Finally || block instanceof AST_Scope || block instanceof AST_Try) && is_last_statement(block.body, stat)); @@ -3690,7 +3689,7 @@ Compressor.prototype.compress = function(node) { function eliminate_dead_code(statements, compressor) { var has_quit; var self = compressor.self(); - if (self instanceof AST_Catch || self instanceof AST_Finally) { + if (self instanceof AST_Catch) { self = compressor.parent(); } else if (self instanceof AST_LabeledStatement) { self = self.body; diff --git a/test/compress/if_return.js b/test/compress/if_return.js index 2ea62f76..7c15c927 100644 --- a/test/compress/if_return.js +++ b/test/compress/if_return.js @@ -963,3 +963,57 @@ issue_4374: { } expect_stdout: "0" } + +issue_5521: { + options = { + if_return: true, + } + input: { + console.log(function() { + if (console) + try { + return "FAIL"; + } finally { + return; + } + }()); + } + expect: { + console.log(function() { + if (console) + try { + return "FAIL"; + } finally { + return; + } + }()); + } + expect_stdout: "undefined" +} + +issue_5523: { + options = { + if_return: true, + } + input: { + console.log(function() { + if (console) + try { + FAIL; + } finally { + return; + } + }()); + } + expect: { + console.log(function() { + if (console) + try { + FAIL; + } finally { + return; + } + }()); + } + expect_stdout: "undefined" +} diff --git a/test/compress/labels.js b/test/compress/labels.js index 42dd3251..c455f3d1 100644 --- a/test/compress/labels.js +++ b/test/compress/labels.js @@ -230,7 +230,6 @@ labels_12: { conditionals: true, dead_code: true, if_return: true, - unused: true, } input: { L: try { @@ -246,13 +245,14 @@ labels_12: { } } expect: { - try { + L: try { if (!console.log("foo")) throw "bar"; } catch (e) { console.log(e); } finally { - console.log("baz") + if (console.log("baz")) + break L; } } expect_stdout: [ @@ -381,3 +381,53 @@ issue_4466_2_toplevel_v8: { } expect_stdout: "PASS" } + +issue_5522: { + options = { + dead_code: true, + } + input: { + console.log(function() { + L: try { + return "FAIL"; + } finally { + break L; + } + return "PASS"; + }()); + } + expect: { + console.log(function() { + L: try { + return "FAIL"; + } finally { + break L; + } + return "PASS"; + }()); + } + expect_stdout: "PASS" +} + +issue_5524: { + options = { + dead_code: true, + } + input: { + L: try { + FAIL; + } finally { + break L; + } + console.log("PASS"); + } + expect: { + L: try { + FAIL; + } finally { + break L; + } + console.log("PASS"); + } + expect_stdout: "PASS" +}