Skip to content

Commit

Permalink
fix corner case in collapse_vars (#3563)
Browse files Browse the repository at this point in the history
fixes #3562
  • Loading branch information
alexlamsl committed Nov 1, 2019
1 parent 6ad8e10 commit 24bb288
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/compress.js
Expand Up @@ -1671,7 +1671,7 @@ merge(Compressor.prototype, {
function symbol_in_lvalues(sym, parent) {
var lvalue = lvalues[sym.name];
if (!lvalue) return;
if (lvalue !== lhs) return !(parent instanceof AST_Call && parent.expression === sym);
if (lvalue !== lhs) return true;
scan_rhs = false;
}

Expand Down
39 changes: 39 additions & 0 deletions test/compress/collapse_vars.js
Expand Up @@ -6348,3 +6348,42 @@ issue_3526_2: {
}
expect_stdout: "PASS"
}

issue_3562: {
options = {
collapse_vars: true,
conditionals: true,
sequences: true,
}
input: {
function f(a) {
console.log("PASS", a);
}
function g(b) {
console.log("FAIL", b);
}
var h;
var c;
if (console) {
h = f;
c = "PASS";
} else {
h = g;
c = "FAIL";
}
h(c);
}
expect: {
function f(a) {
console.log("PASS", a);
}
function g(b) {
console.log("FAIL", b);
}
var h;
var c;
c = console ? (h = f, "PASS") : (h = g, "FAIL"),
h(c);
}
expect_stdout: "PASS PASS"
}

0 comments on commit 24bb288

Please sign in to comment.