diff --git a/lib/compress.js b/lib/compress.js index 9c918e70..ab552c67 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -297,7 +297,9 @@ merge(Compressor.prototype, { && node.operator == "=" && node.left instanceof AST_SymbolRef) { var d = node.left.definition(); - if (HOP(safe_ids, d.id) && safe_to_assign(d, node.right)) { + if (HOP(safe_ids, d.id) + && safe_to_read(d) + && safe_to_assign(d, node.right)) { d.references.push(node.left); d.fixed = function() { return node.right; diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 59f49f35..5a68e79b 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -2110,6 +2110,27 @@ var_assign_5: { expect_stdout: "2 undefined" } +var_assign_6: { + options = { + evaluate: true, + reduce_vars: true, + unused: true, + } + input: { + !function() { + var a = function(){}(a = 1); + console.log(a); + }(); + } + expect: { + !function() { + var a = function(){}(a = 1); + console.log(a); + }(); + } + expect_stdout: "undefined" +} + immutable: { options = { evaluate: true,