Skip to content

Commit

Permalink
fix corner case in collapse_vars (#5278)
Browse files Browse the repository at this point in the history
fixes #5277
  • Loading branch information
alexlamsl committed Jan 8, 2022
1 parent b0df5d7 commit f473b4d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/compress.js
Expand Up @@ -1982,7 +1982,7 @@ Compressor.prototype.compress = function(node) {
abort = true;
folded = make_node(AST_Binary, candidate, {
operator: compound,
left: lhs.fixed ? lhs.fixed.to_binary() : lhs,
left: lhs.fixed && lhs.definition().fixed ? lhs.fixed.to_binary() : lhs,
right: rvalue,
});
}
Expand Down Expand Up @@ -2040,7 +2040,7 @@ Compressor.prototype.compress = function(node) {
});
if (candidate instanceof AST_UnaryPostfix) return make_node(AST_UnaryPrefix, candidate, {
operator: candidate.operator,
expression: lhs.fixed ? lhs.fixed.to_prefix() : lhs,
expression: lhs.fixed && lhs.definition().fixed ? lhs.fixed.to_prefix() : lhs,
});
if (candidate instanceof AST_VarDef) {
var def = candidate.name.definition();
Expand Down
20 changes: 20 additions & 0 deletions test/compress/collapse_vars.js
Expand Up @@ -9790,3 +9790,23 @@ issue_5276: {
}
expect_stdout: "PASS"
}

issue_5277: {
options = {
collapse_vars: true,
reduce_vars: true,
unused: true,
}
input: {
console.log(function() {
var a = function() {
a += null;
a -= 42;
};
}());
}
expect: {
console.log(function() {}());
}
expect_stdout: "undefined"
}

0 comments on commit f473b4d

Please sign in to comment.