diff --git a/lib/compress.js b/lib/compress.js index 3195084a86..725ef91fc0 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1397,15 +1397,24 @@ Compressor.prototype.compress = function(node) { first = false; push(tw, true); } - }) + }); if (!first) pop(tw); - walk_body(node, tw); + var defined_ids = tw.defined_ids; + var safe_ids = tw.safe_ids; + node.body.forEach(function(branch) { + push(tw, true); + branch.walk(tw); + if (aborts(branch)) { + tw.defined_ids = defined_ids; + tw.safe_ids = safe_ids; + } + }); + tw.defined_ids = defined_ids; + tw.safe_ids = safe_ids; return true; }); def(AST_SwitchBranch, function(tw) { - push(tw, true); walk_body(this, tw); - pop(tw); return true; }); def(AST_SymbolCatch, function() { @@ -1501,7 +1510,7 @@ Compressor.prototype.compress = function(node) { } mark_fn_def(tw, d, value); }); - def(AST_Template, function(tw, descend) { + def(AST_Template, function(tw) { var node = this; var tag = node.tag; if (!tag) return; @@ -1549,7 +1558,7 @@ Compressor.prototype.compress = function(node) { if (node.bfinally) node.bfinally.walk(tw); return true; }); - def(AST_Unary, function(tw, descend) { + def(AST_Unary, function(tw) { var node = this; if (!UNARY_POSTFIX[node.operator]) return; var exp = node.expression; diff --git a/test/compress/functions.js b/test/compress/functions.js index 7c4742257a..be9ede3d3f 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -5720,9 +5720,9 @@ issue_3929: { var abc = function f() { (function() { switch (f) { - default: + default: var abc = 0; - case 0: + case 0: abc.p; } console.log(typeof f); @@ -5736,10 +5736,9 @@ issue_3929: { var abc = function f() { (function() { switch (f) { - default: - var abc = 0; - case 0: - abc.p; + default: + case 0: + 0..p; } console.log(typeof f); })(); diff --git a/test/compress/switches.js b/test/compress/switches.js index 0502db78d7..2e23f3e3b5 100644 --- a/test/compress/switches.js +++ b/test/compress/switches.js @@ -1688,3 +1688,42 @@ issue_5543_2: { } expect_stdout: "PASS" } + +issue_5890: { + options = { + pure_getters: "strict", + reduce_vars: true, + side_effects: true, + } + input: { + var a = {}; + a.p; + try { + switch (42) { + default: + a = null; + case false: + a.q; + } + console.log("FAIL"); + } catch (e) { + console.log("PASS"); + } + } + expect: { + var a = {}; + a.p; + try { + switch (42) { + default: + a = null; + case false: + a.q; + } + console.log("FAIL"); + } catch (e) { + console.log("PASS"); + } + } + expect_stdout: "PASS" +}