fix corner case in collapse_vars (#5513)

fixes #5512
This commit is contained in:
Alex Lam S.L
2022-06-13 00:55:15 +01:00
committed by GitHub
parent b6f250f5c9
commit 4382bfe848
2 changed files with 46 additions and 11 deletions

View File

@@ -2351,20 +2351,25 @@ Compressor.prototype.compress = function(node) {
// Scan computed keys, static fields & initializers in class
if (node instanceof AST_Class) {
if (node.name) node.name = node.name.transform(tt);
if (node.extends) node.extends = node.extends.transform(tt);
node.properties.reduce(function(props, prop) {
if (!abort && node.extends) node.extends = node.extends.transform(tt);
var fields = [], stats = [];
for (var i = 0; !abort && i < node.properties.length; i++) {
var prop = node.properties[i];
if (prop.key instanceof AST_Node) prop.key = prop.key.transform(tt);
if (prop.static) {
if (prop instanceof AST_ClassField) {
if (prop.value) props.push(prop);
} else if (prop instanceof AST_ClassInit) {
props.unshift(prop);
}
if (!prop.static) continue;
if (prop instanceof AST_ClassField) {
if (prop.value) fields.push(prop);
} else if (prop instanceof AST_ClassInit) {
[].push.apply(stats, prop.value.body);
}
return props;
}, []).forEach(function(prop) {
}
for (var i = 0; !abort && i < stats.length; i++) {
stats[i].transform(tt);
}
for (var i = 0; !abort && i < fields.length; i++) {
var prop = fields[i];
prop.value = prop.value.transform(tt);
});
}
return node;
}
// Scan object only in a for-in/of statement