Skip to content

Commit

Permalink
fix corner case in collapse_vars (#4869)
Browse files Browse the repository at this point in the history
fixes #4868
  • Loading branch information
alexlamsl committed Apr 24, 2021
1 parent a2b1b96 commit a1a212f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/compress.js
Expand Up @@ -2563,8 +2563,13 @@ merge(Compressor.prototype, {
if (is_lhs_read_only(value, compressor)) return;
var referenced = def.references.length - def.replaced;
if (referenced < 2) return;
candidate = candidate.clone();
candidate[candidate instanceof AST_Assign ? "right" : "value"] = value;
var expr = candidate.clone();
expr[expr instanceof AST_Assign ? "right" : "value"] = value;
if (candidate.name_index >= 0) {
expr.name_index = candidate.name_index;
expr.arg_index = candidate.arg_index;
}
candidate = expr;
}
return value_def = def;
}
Expand Down
20 changes: 20 additions & 0 deletions test/compress/collapse_vars.js
Expand Up @@ -9010,3 +9010,23 @@ issue_4865: {
}
expect_stdout: true
}

issue_4868: {
options = {
collapse_vars: true,
unused: true,
}
input: {
var a;
(function(b) {
console.log(b[0]);
})(a = [ "PASS" ], a = [ "FAIL" ]);
}
expect: {
var a;
(function(b) {
console.log(b[0]);
})(a = [ "PASS" ], a = [ "FAIL" ]);
}
expect_stdout: "PASS"
}

0 comments on commit a1a212f

Please sign in to comment.