diff options
-rw-r--r-- | lib/compress.js | 7 | ||||
-rw-r--r-- | test/compress/collapse_vars.js | 25 |
2 files changed, 29 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js index 312ce728..832f64f2 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1044,13 +1044,15 @@ merge(Compressor.prototype, { // but are otherwise not safe to scan into or beyond them. var sym; if (node instanceof AST_Call + || node instanceof AST_Exit + && (side_effects || lhs instanceof AST_PropAccess || may_modify(lhs)) || node instanceof AST_PropAccess && (side_effects || node.expression.may_throw_on_access(compressor)) || node instanceof AST_SymbolRef && !(parent instanceof AST_Assign && parent.operator == "=" && parent.left === node) - && (lvalues[node.name] || may_modify(node)) + && (lvalues[node.name] || side_effects && may_modify(node)) || node instanceof AST_VarDef && node.value - && (node.name.name in lvalues || may_modify(node.name)) + && (node.name.name in lvalues || side_effects && may_modify(node.name)) || (sym = is_lhs(node.left, node)) && (sym instanceof AST_PropAccess || sym.name in lvalues) || may_throw @@ -1356,7 +1358,6 @@ merge(Compressor.prototype, { } function may_modify(sym) { - if (!side_effects) return false; var def = sym.definition(); if (def.orig.length == 1 && def.orig[0] instanceof AST_SymbolDefun) return false; if (def.scope !== scope) return true; diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index f56face6..948389b1 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -4191,6 +4191,31 @@ return_3: { expect_stdout: "0" } +return_4: { + options = { + collapse_vars: true, + } + input: { + var a = "FAIL"; + (function(b) { + a = "PASS"; + return; + b(a); + })(); + console.log(a); + } + expect: { + var a = "FAIL"; + (function(b) { + a = "PASS"; + return; + b(a); + })(); + console.log(a); + } + expect_stdout: "PASS" +} + issue_2858: { options = { collapse_vars: true, |