fix corner case in reduce_vars (#5687)

This commit is contained in:
Alex Lam S.L
2022-09-29 19:00:37 +01:00
committed by GitHub
parent bd5fc4cb1b
commit e1e3516397
2 changed files with 234 additions and 2 deletions

View File

@@ -497,6 +497,7 @@ Compressor.prototype.compress = function(node) {
function has_escaped(d, scope, node, parent) {
if (parent instanceof AST_Assign) return parent.operator == "=" && parent.right === node;
if (parent instanceof AST_Call) return parent.expression !== node || parent instanceof AST_New;
if (parent instanceof AST_ClassField) return parent.value === node && !parent.static;
if (parent instanceof AST_Exit) return parent.value === node && scope.resolve() !== d.scope.resolve();
if (parent instanceof AST_VarDef) return parent.value === node;
}
@@ -1164,7 +1165,11 @@ Compressor.prototype.compress = function(node) {
if (node.extends) node.extends.walk(tw);
var props = node.properties.filter(function(prop) {
reset_flags(prop);
if (prop.key instanceof AST_Node) prop.key.walk(tw);
if (prop.key instanceof AST_Node) {
tw.push(prop);
prop.key.walk(tw);
tw.pop();
}
return prop.value;
});
if (node.name) {
@@ -1184,6 +1189,7 @@ Compressor.prototype.compress = function(node) {
}
}
props.forEach(function(prop) {
tw.push(prop);
if (!prop.static || is_static_field_or_init(prop) && prop.value.contains_this()) {
push(tw);
prop.value.walk(tw);
@@ -1191,6 +1197,7 @@ Compressor.prototype.compress = function(node) {
} else {
prop.value.walk(tw);
}
tw.pop();
});
return true;
});
@@ -12296,7 +12303,7 @@ Compressor.prototype.compress = function(node) {
var single_use = def.single_use && !(parent instanceof AST_Call && parent.is_expr_pure(compressor));
if (single_use) {
if (is_lambda(fixed)) {
if ((def.scope !== self.scope.resolve() || def.in_loop)
if ((def.scope !== self.scope.resolve(true) || def.in_loop)
&& (!compressor.option("reduce_funcs") || def.escaped.depth == 1 || fixed.inlined)) {
single_use = false;
} else if (def.redefined()) {