From 316245ee12ec73427b5cd9dc9125acbf22b87fb3 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 13 Feb 2022 00:22:34 +0000 Subject: [PATCH] fix corner case in `merge_vars` (#5353) fixes #5352 --- lib/compress.js | 19 ++++++++++++++++++- test/compress/classes.js | 26 ++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index a7b6397274..b0a85dddad 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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); } @@ -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; diff --git a/test/compress/classes.js b/test/compress/classes.js index 4471663d7c..2713a24831 100644 --- a/test/compress/classes.js +++ b/test/compress/classes.js @@ -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" +}