diff --git a/lib/compress.js b/lib/compress.js index 82543be39b..19b7256049 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -601,6 +601,19 @@ Compressor.prototype.compress = function(node) { fn.enclosed.forEach(function(d) { if (fn.variables.get(d.name) === d) return; if (safe_to_read(tw, d)) return; + d.single_use = false; + var fixed = d.fixed; + if (typeof fixed == "function") fixed = fixed(); + if (fixed instanceof AST_Lambda) { + var safe_ids = fixed.safe_ids; + switch (safe_ids) { + case null: + case false: + return; + default: + if (safe_ids && safe_ids.seq !== tw.safe_ids.seq) return; + } + } d.fixed = false; }); } @@ -648,6 +661,7 @@ Compressor.prototype.compress = function(node) { tw.defined_ids = defined_ids; var safe_ids = Object.create(tw.safe_ids); if (!sequential) safe_ids.seq = {}; + if (conditional) safe_ids.cond = true; tw.safe_ids = safe_ids; } @@ -1009,7 +1023,7 @@ Compressor.prototype.compress = function(node) { walk_assign(); right.parent_scope.resolve().fn_defs.push(right); right.safe_ids = null; - if (!ld.fixed || !node.write_only) mark_fn_def(tw, ld, right); + if (!ld.fixed || !node.write_only || tw.safe_ids.cond) mark_fn_def(tw, ld, right); return true; } if (scan) { diff --git a/test/compress/pure_getters.js b/test/compress/pure_getters.js index 1e6509e1c5..eddd04b1c0 100644 --- a/test/compress/pure_getters.js +++ b/test/compress/pure_getters.js @@ -1716,7 +1716,7 @@ issue_5856: { expect_stdout: "PASS" } -issue_5917: { +issue_5917_1: { options = { pure_getters: "strict", reduce_vars: true, @@ -1751,3 +1751,46 @@ issue_5917: { } expect_stdout: "PASS" } + +issue_5917_2: { + options = { + passes: 2, + pure_getters: "strict", + reduce_vars: true, + side_effects: true, + toplevel: true, + } + input: { + var b; + if (!console) { + b = function() {}; + FAIL(f); + } + function f() { + b.p; + } + try { + f(); + console.log("FAIL"); + } catch (e) { + console.log("PASS"); + } + } + expect: { + var b; + if (!console) { + b = function() {}; + FAIL(f); + } + function f() { + b.p; + } + try { + f(); + console.log("FAIL"); + } catch (e) { + console.log("PASS"); + } + } + expect_stdout: "PASS" +}