Skip to content

Commit

Permalink
fix corner case in reduce_vars (#5464)
Browse files Browse the repository at this point in the history
fixes #5463
  • Loading branch information
alexlamsl authored May 23, 2022
1 parent c2ca7b7 commit d4caa97
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,14 +766,14 @@ Compressor.prototype.compress = function(node) {
function make_fixed_default(compressor, node, save) {
var prev_save, prev_seq;
return function() {
if (prev_seq === node) return node;
var current = save();
var ev;
if (!is_undefined(current, compressor) && (ev = fuzzy_eval(compressor, current, true)) !== undefined) {
return ev instanceof AST_Node ? node : current;
}
if (prev_save !== current) {
var ev = fuzzy_eval(compressor, current, true);
if (ev instanceof AST_Node) {
prev_seq = node;
} else if (prev_save !== current) {
prev_save = current;
prev_seq = make_sequence(node, [ current, node.value ]);
prev_seq = ev === undefined ? make_sequence(node, [ current, node.value ]) : current;
}
return prev_seq;
};
Expand Down Expand Up @@ -9152,6 +9152,7 @@ Compressor.prototype.compress = function(node) {

function fuzzy_eval(compressor, node, nullish) {
if (node.truthy) return true;
if (is_undefined(node)) return undefined;
if (node.falsy && !nullish) return false;
if (node.is_truthy()) return true;
return node.evaluate(compressor, true);
Expand Down
26 changes: 26 additions & 0 deletions test/compress/default-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -2395,3 +2395,29 @@ issue_5448_4: {
expect_stdout: "PASS"
node_version: ">=6"
}

issue_5463: {
options = {
collapse_vars: true,
conditionals: true,
evaluate: true,
reduce_vars: true,
toplevel: true,
unsafe: true,
}
input: {
if (console.log("PASS"))
var a = void 0,
b = void 0,
b = ([ a = FAIL ] = b && b);
}
expect: {
var a, b, b;
console.log("PASS") && (
b = a = void 0,
b = [a = FAIL] = a && a
);
}
expect_stdout: "PASS"
node_version: ">=6"
}

0 comments on commit d4caa97

Please sign in to comment.