Skip to content

Commit

Permalink
fix corner case in collapse_vars (#3745)
Browse files Browse the repository at this point in the history
fixes #3744
  • Loading branch information
alexlamsl authored Mar 6, 2020
1 parent bca52fc commit bdc8ef2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,10 @@ merge(Compressor.prototype, {
function is_last_node(node, parent) {
if (node instanceof AST_Call) {
var fn = node.expression;
if (fn instanceof AST_SymbolRef) fn = fn.fixed_value();
if (fn instanceof AST_SymbolRef) {
if (fn.definition().recursive_refs > 0) return true;
fn = fn.fixed_value();
}
if (!(fn instanceof AST_Lambda)) return true;
if (fn.collapse_scanning) return false;
fn.collapse_scanning = true;
Expand Down
41 changes: 41 additions & 0 deletions test/compress/collapse_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -7765,3 +7765,44 @@ issue_3700: {
}
expect_stdout: "PASS"
}

issue_3744: {
options = {
collapse_vars: true,
inline: true,
reduce_vars: true,
unused: true,
}
input: {
(function f(a) {
({
get p() {
switch (1) {
case 0:
f((a = 2, 3));
case 1:
console.log(function g(b) {
return b || "PASS";
}());
}
}
}).p;
})();
}
expect: {
(function f(a) {
({
get p() {
switch (1) {
case 0:
f();
case 1:
console.log(b || "PASS");
}
var b;
}
}).p;
})();
}
expect_stdout: "PASS"
}

0 comments on commit bdc8ef2

Please sign in to comment.