diff --git a/lib/compress.js b/lib/compress.js index 3820a3ad..e61954c6 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1815,7 +1815,11 @@ merge(Compressor.prototype, { var node = compressor.self(), level = 0; do { if (node instanceof AST_Catch) { - if (!compressor.parent(level).bfinally) level++; + if (compressor.parent(level).bfinally) { + if (!in_try) in_try = {}; + in_try.bfinally = true; + } + level++; } else if (node instanceof AST_Finally) { level++; } else if (node instanceof AST_IterationStatement) { @@ -1824,7 +1828,9 @@ merge(Compressor.prototype, { scope = node; break; } else if (node instanceof AST_Try) { - if (!in_try) in_try = node; + if (!in_try) in_try = {}; + if (node.bcatch) in_try.bcatch = true; + if (node.bfinally) in_try.bfinally = true; } } while (node = compressor.parent(level++)); } diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 4e133768..0df9d72f 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -9412,3 +9412,73 @@ issue_4977_2: { } expect_stdout: "PASS PASS" } + +issue_5112_1: { + options = { + collapse_vars: true, + } + input: { + console.log(function(a) { + try { + try { + if (console + (a = "PASS", "")) + return "FAIL 1"; + a.p; + } catch (e) {} + } finally { + return a; + } + }("FAIL 2")); + } + expect: { + console.log(function(a) { + try { + try { + if (console + (a = "PASS", "")) + return "FAIL 1"; + a.p; + } catch (e) {} + } finally { + return a; + } + }("FAIL 2")); + } + expect_stdout: "PASS" +} + +issue_5112_2: { + options = { + collapse_vars: true, + } + input: { + console.log(function(a) { + try { + return function() { + try { + if (console + (a = "PASS", "")) + return "FAIL 1"; + a.p; + } catch (e) {} + }(); + } finally { + return a; + } + }("FAIL 2")); + } + expect: { + console.log(function(a) { + try { + return function() { + try { + if (console + (a = "PASS", "")) + return "FAIL 1"; + a.p; + } catch (e) {} + }(); + } finally { + return a; + } + }("FAIL 2")); + } + expect_stdout: "PASS" +}