Skip to content

Commit

Permalink
fix corner case in collapse_vars (#5926)
Browse files Browse the repository at this point in the history
fixes #5924
fixes #5925
  • Loading branch information
alexlamsl authored Aug 21, 2024
1 parent 23f98ba commit 4a92cdc
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -3409,6 +3409,7 @@ Compressor.prototype.compress = function(node) {
var find_arguments = scope.uses_arguments && !compressor.has_directive("use strict");
var scan_toplevel = scope instanceof AST_Toplevel;
var tw = new TreeWalker(function(node) {
if (node.inlined_node) node.inlined_node.walk(tw);
var value;
if (node instanceof AST_SymbolRef) {
value = node.fixed_value();
Expand Down
65 changes: 65 additions & 0 deletions test/compress/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9076,3 +9076,68 @@ issue_5895_2: {
"foo",
]
}

issue_5924: {
options = {
collapse_vars: true,
inline: true,
reduce_vars: true,
toplevel: true,
}
input: {
var a = 42;
function f() {
return a - 41;
}
function g() {
return f;
}
var b = f();
a--;
console.log(b ? "PASS" : "FAIL");
}
expect: {
var a = 42;
function f() {
return a - 41;
}
function g() {
return f;
}
var b = f();
a--;
console.log(b ? "PASS" : "FAIL");
}
expect_stdout: "PASS"
}

issue_5925: {
options = {
collapse_vars: true,
inline: true,
reduce_vars: true,
}
input: {
var a = 42;
console.log(function() {
function f() {
return +a - 41;
}
var b = f(f);
a--;
return b;
}() ? "PASS" : "FAIL");
}
expect: {
var a = 42;
console.log(function() {
function f() {
return +a - 41;
}
var b = f(f);
a--;
return b;
}() ? "PASS" : "FAIL");
}
expect_stdout: "PASS"
}

0 comments on commit 4a92cdc

Please sign in to comment.