Skip to content

Commit

Permalink
fix corner case in merge_vars (#5353)
Browse files Browse the repository at this point in the history
fixes #5352
  • Loading branch information
alexlamsl committed Feb 13, 2022
1 parent 63b92ea commit 316245e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/compress.js
Expand Up @@ -6029,7 +6029,7 @@ Compressor.prototype.compress = function(node) {
if (node instanceof AST_Call) {
var exp = node.expression;
var tail = exp.tail_node();
if (!is_lambda(tail)) {
if (!(tail instanceof AST_LambdaExpression)) {
descend();
return mark_expression(exp);
}
Expand All @@ -6042,6 +6042,23 @@ Compressor.prototype.compress = function(node) {
tail.walk(tw);
return true;
}
if (node instanceof AST_Class) {
if (node.name) node.name.walk(tw);
if (node.extends) node.extends.walk(tw);
node.properties.filter(function(prop) {
if (prop.key instanceof AST_Node) prop.key.walk(tw);
return prop.value;
}).forEach(function(prop) {
if (prop.static) {
prop.value.walk(tw);
} else {
push(tw);
prop.value.walk(tw);
pop(tw);
}
});
return true;
}
if (node instanceof AST_Conditional) {
walk_cond(node.condition, node.consequent, node.alternative);
return true;
Expand Down
26 changes: 26 additions & 0 deletions test/compress/classes.js
Expand Up @@ -2476,3 +2476,29 @@ issue_5322: {
expect_stdout: "42"
node_version: ">=12"
}

issue_5352: {
options = {
merge_vars: true,
}
input: {
function f(a) {
var b;
new class {
[b = console.log(a)] = b;
}(a.p);
}
f("PASS");
}
expect: {
function f(a) {
var b;
new class {
[b = console.log(a)] = b;
}(a.p);
}
f("PASS");
}
expect_stdout: "PASS"
node_version: ">=12"
}

0 comments on commit 316245e

Please sign in to comment.