Skip to content

Commit

Permalink
fix corner case in collapse_vars (#4866)
Browse files Browse the repository at this point in the history
fixes #4865
  • Loading branch information
alexlamsl committed Apr 24, 2021
1 parent 10dd9d4 commit c296a63
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/compress.js
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions test/compress/collapse_vars.js
Expand Up @@ -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
}

0 comments on commit c296a63

Please sign in to comment.