diff --git a/lib/compress.js b/lib/compress.js index 3ea673b3..b89e0df9 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -838,7 +838,7 @@ merge(Compressor.prototype, { if (node instanceof AST_Call || node instanceof AST_Exit || node instanceof AST_PropAccess - && node.expression.may_throw_on_access(compressor) + && (side_effects || node.expression.may_throw_on_access(compressor)) || node instanceof AST_SymbolRef && (lvalues[node.name] || side_effects && !references_in_scope(node.definition())) diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 4baa1f02..13fff97a 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -2875,3 +2875,79 @@ issue_2364_7: { } expect_stdout: "PASS" } + +issue_2364_8: { + options = { + collapse_vars: true, + pure_getters: true, + } + input: { + function f(a, b, c) { + var d = a[b.f = function() { + return "PASS"; + }]; + return c.f(d); + } + var o = { + f: function() { + return "FAIL"; + } + }; + console.log(f({}, o, o)); + } + expect: { + function f(a, b, c) { + var d = a[b.f = function() { + return "PASS"; + }]; + return c.f(d); + } + var o = { + f: function() { + return "FAIL"; + } + }; + console.log(f({}, o, o)); + } + expect_stdout: "PASS" +} + +issue_2364_9: { + options = { + collapse_vars: true, + pure_getters: true, + } + input: { + function f(a, b) { + var d = a(); + return b.f(d); + } + var o = { + f: function() { + return "FAIL"; + } + }; + console.log(f(function() { + o.f = function() { + return "PASS"; + }; + }, o)); + } + expect: { + function f(a, b) { + var d = a(); + return b.f(d); + } + var o = { + f: function() { + return "FAIL"; + } + }; + console.log(f(function() { + o.f = function() { + return "PASS"; + }; + }, o)); + } + expect_stdout: "PASS" +}