diff options
-rw-r--r-- | lib/compress.js | 2 | ||||
-rw-r--r-- | test/compress/collapse_vars.js | 71 |
2 files changed, 70 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js index d4a72d74..33b4ef00 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -812,7 +812,7 @@ merge(Compressor.prototype, { var sym; if (node instanceof AST_Call || node instanceof AST_Exit - || node instanceof AST_PropAccess + || node instanceof AST_PropAccess && node.has_side_effects(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 ecd18610..631f5b29 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -1834,9 +1834,9 @@ issue_1858: { } expect: { console.log(function(x) { - var a = {}, b = a.b = x; + var a = {}, b = a.b = 1; return a.b + b; - }(1)); + }()); } expect_stdout: "2" } @@ -2521,3 +2521,70 @@ issue_2319_3: { } expect_stdout: "true" } + +prop_side_effects_1: { + options = { + collapse_vars: true, + evaluate: true, + pure_getters: "strict", + reduce_vars: true, + toplevel: true, + unsafe: true, + unused: true, + } + input: { + var C = 1; + console.log(C); + var obj = { + bar: function() { + return C + C; + } + }; + console.log(obj.bar()); + } + expect: { + console.log(1); + console.log({ + bar: function() { + return 2; + } + }.bar()); + } + expect_stdout: [ + "1", + "2", + ] +} + +prop_side_effects_2: { + options = { + collapse_vars: true, + evaluate: true, + inline: true, + passes: 2, + pure_getters: "strict", + reduce_vars: true, + side_effects: true, + toplevel: true, + unsafe: true, + unused: true, + } + input: { + var C = 1; + console.log(C); + var obj = { + bar: function() { + return C + C; + } + }; + console.log(obj.bar()); + } + expect: { + console.log(1); + console.log(2); + } + expect_stdout: [ + "1", + "2", + ] +} |