Skip to content

Commit

Permalink
fix corner case in merge_vars (#5424)
Browse files Browse the repository at this point in the history
fixes #5423
  • Loading branch information
alexlamsl authored Apr 19, 2022
1 parent 1bc0fcc commit fbdb7ee
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 17 deletions.
34 changes: 17 additions & 17 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -6081,18 +6081,15 @@ Compressor.prototype.compress = function(node) {
}
if (node instanceof AST_Call) {
var exp = node.expression;
var tail = exp.tail_node();
if (!(tail instanceof AST_LambdaExpression)) {
if (exp instanceof AST_LambdaExpression) {
node.args.forEach(function(arg) {
arg.walk(tw);
});
exp.walk(tw);
} else {
descend();
return mark_expression(exp);
mark_expression(exp);
}
if (exp !== tail) exp.expressions.slice(0, -1).forEach(function(node) {
node.walk(tw);
});
node.args.forEach(function(arg) {
arg.walk(tw);
});
tail.walk(tw);
return true;
}
if (node instanceof AST_Class) {
Expand Down Expand Up @@ -6172,6 +6169,8 @@ Compressor.prototype.compress = function(node) {
if (node === self) root = segment;
if (node instanceof AST_Lambda) {
if (node.name) references[node.name.definition().id] = false;
var parent = tw.parent();
var in_iife = parent && parent.TYPE == "Call" && parent.expression === node;
var marker = node.uses_arguments && !tw.has_directive("use strict") ? function(node) {
if (node instanceof AST_SymbolFunarg) references[node.definition().id] = false;
} : function(node) {
Expand All @@ -6187,11 +6186,13 @@ Compressor.prototype.compress = function(node) {
|| node.parent_scope.find_variable(ref.name) === def)) {
references[def.id] = false;
references[ldef.id] = false;
} else {
} else if (in_iife) {
var save = segment;
pop();
mark(ref, true);
segment = save;
} else {
mark(ref, true);
}
return true;
});
Expand All @@ -6214,7 +6215,8 @@ Compressor.prototype.compress = function(node) {
} else {
descend();
}
return mark_expression(exp);
mark_expression(exp);
return true;
}
if (node instanceof AST_Switch) {
node.expression.walk(tw);
Expand Down Expand Up @@ -6313,11 +6315,9 @@ Compressor.prototype.compress = function(node) {
}

function mark_expression(exp) {
if (compressor.option("ie")) {
var sym = root_expr(exp);
if (sym instanceof AST_SymbolRef) sym.walk(tw);
}
return true;
if (!compressor.option("ie")) return;
var sym = root_expr(exp);
if (sym instanceof AST_SymbolRef) sym.walk(tw);
}

function walk_cond(condition, consequent, alternative) {
Expand Down
31 changes: 31 additions & 0 deletions test/compress/destructured.js
Original file line number Diff line number Diff line change
Expand Up @@ -3535,3 +3535,34 @@ issue_5405_2: {
expect_stdout: "PASS"
node_version: ">=6"
}

issue_5423: {
options = {
merge_vars: true,
toplevel: true,
}
input: {
var a, b;
function f({
[function() {
if (++a)
return 42;
}()]: c
}) {}
f(b = f);
console.log(typeof b);
}
expect: {
var a, b;
function f({
[function() {
if (++a)
return 42;
}()]: c
}) {}
f(b = f);
console.log(typeof b);
}
expect_stdout: "function"
node_version: ">=6"
}

0 comments on commit fbdb7ee

Please sign in to comment.