diff --git a/lib/compress.js b/lib/compress.js index b515c4259c..80e967ed1f 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1275,7 +1275,14 @@ Compressor.prototype.compress = function(node) { descend(); var node = this; var expr = node.expression; - if (!node.optional && expr instanceof AST_SymbolRef) access(tw, expr.definition()); + if (!node.optional) { + while (expr instanceof AST_Assign && expr.operator == "=") { + var lhs = expr.left; + if (lhs instanceof AST_SymbolRef) access(tw, lhs.definition()); + expr = expr.right; + } + if (expr instanceof AST_SymbolRef) access(tw, expr.definition()); + } return true; }); def(AST_For, function(tw, descend, compressor) { @@ -1385,6 +1392,11 @@ Compressor.prototype.compress = function(node) { pop(tw); } else { descend(); + while (expr instanceof AST_Assign && expr.operator == "=") { + var lhs = expr.left; + if (lhs instanceof AST_SymbolRef) access(tw, lhs.definition()); + expr = expr.right; + } if (expr instanceof AST_SymbolRef) access(tw, expr.definition()); } return true; @@ -8056,6 +8068,7 @@ Compressor.prototype.compress = function(node) { if (node.write_only === "p" && node.right.may_throw_on_access(compressor, true)) return; var assign = props.assign; if (assign) { + initializations.add(node_def.id, assign.left); assign.write_only = true; assign.walk(tw); } diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js index fffa69419f..06c0f46ae4 100644 --- a/test/compress/drop-unused.js +++ b/test/compress/drop-unused.js @@ -3814,3 +3814,59 @@ issue_5533_drop_fargs: { } expect_stdout: "PASS" } + +issue_5908_1: { + options = { + collapse_vars: true, + pure_getters: "strict", + reduce_vars: true, + unused: true, + } + input: { + var a = function(b) { + function f() {} + b = f.prototype; + b.p = 42; + b.q = "PASS"; + return f; + }(); + console.log(a.prototype.q); + } + expect: { + var a = function(b) { + function f() {} + (b = f.prototype).p = 42; + b.q = "PASS"; + return f; + }(); + console.log(a.prototype.q); + } + expect_stdout: "PASS" +} + +issue_5908_2: { + options = { + pure_getters: "strict", + reduce_vars: true, + unused: true, + } + input: { + var a = function(b) { + function f() {} + (b = f.prototype).p = 42; + b.q = "PASS"; + return f; + }(); + console.log(a.prototype.q); + } + expect: { + var a = function(b) { + function f() {} + (b = f.prototype).p = 42; + b.q = "PASS"; + return f; + }(); + console.log(a.prototype.q); + } + expect_stdout: "PASS" +} diff --git a/test/compress/functions.js b/test/compress/functions.js index 42a2acf995..d900d32809 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -7139,7 +7139,7 @@ reduce_cross_reference_2_toplevel: { reduce_cross_reference_3: { options = { collapse_vars: true, - passes: 3, + passes: 4, pure_getters: "strict", reduce_vars: true, sequences: true,