Skip to content

Commit

Permalink
fix corner case in collapse_vars (#3582)
Browse files Browse the repository at this point in the history
fixes #3581
  • Loading branch information
alexlamsl committed Nov 13, 2019
1 parent d6fd18d commit fe65ce9
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/compress.js
Expand Up @@ -1090,7 +1090,7 @@ merge(Compressor.prototype, {
scope = node;
break;
} else if (node instanceof AST_Try) {
in_try = true;
in_try = node;
}
} while (node = compressor.parent(level++));
}
Expand Down Expand Up @@ -1321,6 +1321,10 @@ merge(Compressor.prototype, {
function is_last_node(node, parent) {
if (node instanceof AST_Call) return true;
if (node instanceof AST_Exit) {
if (in_try) {
if (in_try.bfinally) return true;
if (in_try.bcatch && node instanceof AST_Throw) return true;
}
return side_effects || lhs instanceof AST_PropAccess || may_modify(lhs);
}
if (node instanceof AST_Function) {
Expand Down
60 changes: 60 additions & 0 deletions test/compress/collapse_vars.js
Expand Up @@ -6468,3 +6468,63 @@ issue_3573: {
}
expect_stdout: "1"
}

issue_3581_1: {
options = {
collapse_vars: true,
}
input: {
var a = "PASS", b = "FAIL";
try {
b = "PASS";
if (a) throw 0;
b = 1 + b;
a = "FAIL";
} catch (e) {}
console.log(a, b);
}
expect: {
var a = "PASS", b = "FAIL";
try {
b = "PASS";
if (a) throw 0;
b = 1 + b;
a = "FAIL";
} catch (e) {}
console.log(a, b);
}
expect_stdout: "PASS PASS"
}

issue_3581_2: {
options = {
collapse_vars: true,
}
input: {
(function() {
var a = "PASS", b = "FAIL";
try {
b = "PASS";
if (a) return;
b = 1 + b;
a = "FAIL";
} finally {
console.log(a, b);
}
})();
}
expect: {
(function() {
var a = "PASS", b = "FAIL";
try {
b = "PASS";
if (a) return;
b = 1 + b;
a = "FAIL";
} finally {
console.log(a, b);
}
})();
}
expect_stdout: "PASS PASS"
}

0 comments on commit fe65ce9

Please sign in to comment.