diff options
-rw-r--r-- | lib/compress.js | 7 | ||||
-rw-r--r-- | test/compress/collapse_vars.js | 17 |
2 files changed, 21 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js index 6f102e7f..4c9026d1 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -2560,7 +2560,7 @@ merge(Compressor.prototype, { if (def.undeclared) return; if (is_arguments(def)) return; if (value !== rhs) { - if (value.is_immutable()) return; + if (is_lhs_read_only(value, compressor)) return; var referenced = def.references.length - def.replaced; if (referenced < 2) return; candidate = candidate.clone(); @@ -7330,8 +7330,9 @@ merge(Compressor.prototype, { def(AST_Assign, function(compressor) { var left = this.left; if (left instanceof AST_PropAccess) { - if (left.expression.may_throw_on_access(compressor, true)) return this; - if (compressor.has_directive("use strict") && left.expression.is_constant()) return this; + var expr = left.expression; + if (expr.may_throw_on_access(compressor, true)) return this; + if (compressor.has_directive("use strict") && expr.is_constant()) return this; } if (left.has_side_effects(compressor)) return this; var right = this.right; diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 451681b6..4051bb14 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -8993,3 +8993,20 @@ issue_4852: { } expect_stdout: "PASS" } + +issue_4865: { + options = { + collapse_vars: true, + } + input: { + var NaN; + var a = NaN = "PASS"; + console.log(a, NaN); + } + expect: { + var NaN; + var a = NaN = "PASS"; + console.log(a, NaN); + } + expect_stdout: true +} |