fix corner case in merge_vars (#5424)

fixes #5423
This commit is contained in:
Alex Lam S.L
2022-04-19 09:04:06 +08:00
committed by GitHub
parent 1bc0fccc8c
commit fbdb7eeda3
2 changed files with 48 additions and 17 deletions

View File

@@ -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) {
@@ -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) {
@@ -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;
});
@@ -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);
@@ -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) {

View File

@@ -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"
}