Skip to content

Commit

Permalink
fix corner case in collapse_vars (#4909)
Browse files Browse the repository at this point in the history
fixes #4908
  • Loading branch information
alexlamsl committed May 4, 2021
1 parent ce3c35f commit 3094eaa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/compress.js
Expand Up @@ -1911,6 +1911,7 @@ merge(Compressor.prototype, {
right: ref,
});
}
ref.fixed = false;
def.replaced++;
return ref;
}
Expand Down Expand Up @@ -1991,6 +1992,7 @@ merge(Compressor.prototype, {
&& !compressor.exposed(def);
value_def.last_ref = false;
value_def.single_use = false;
CHANGED = true;
}
if (replaced && !remove_candidate(candidate)) statements.splice(stat_index, 1);
}
Expand Down
25 changes: 24 additions & 1 deletion test/compress/collapse_vars.js
Expand Up @@ -9049,7 +9049,7 @@ issue_4874: {
}
expect: {
var a;
null;
a = null;
(function(b) {
for (var c in a && a[console.log("PASS")])
console;
Expand Down Expand Up @@ -9107,3 +9107,26 @@ issue_4895: {
}
expect_stdout: "42 42"
}

issue_4908: {
options = {
collapse_vars: true,
join_vars: true,
reduce_vars: true,
toplevel: true,
}
input: {
var a = 0;
var b;
console || a++;
var c = d = a, d = [ c && c, d += 42 ];
console.log(d[1]);
}
expect: {
var a = 0, b;
console || a++;
var c = d = a, d = [ d && d, d += 42 ];
console.log(d[1]);
}
expect_stdout: "42"
}
4 changes: 2 additions & 2 deletions test/compress/functions.js
Expand Up @@ -6107,7 +6107,7 @@ reduce_cross_reference_2: {
reduce_cross_reference_2_toplevel: {
options = {
collapse_vars: true,
passes: 2,
passes: 3,
pure_getters: "strict",
reduce_vars: true,
sequences: true,
Expand Down Expand Up @@ -6150,7 +6150,7 @@ reduce_cross_reference_3: {
reduce_cross_reference_3_toplevel: {
options = {
collapse_vars: true,
passes: 2,
passes: 3,
pure_getters: "strict",
reduce_vars: true,
sequences: true,
Expand Down

0 comments on commit 3094eaa

Please sign in to comment.