enhance collapse_vars (#5186)

closes #5182
This commit is contained in:
Alex Lam S.L
2021-11-24 09:28:36 +00:00
committed by GitHub
parent dc9e1ff0b1
commit 1a8f2ecc65
3 changed files with 101 additions and 10 deletions

View File

@@ -2906,8 +2906,9 @@ merge(Compressor.prototype, {
if (!value) {
value = node;
var def = node.definition();
var escaped = node.fixed && node.fixed.escaped || def.escaped;
if (!def.undeclared
&& (def.assignments || !def.escaped || def.escaped.cross_scope)
&& (def.assignments || !escaped || escaped.cross_scope)
&& (has_escaped(def, node.scope, node, tw.parent()) || !same_scope(def))) {
well_defined = false;
}
@@ -2915,8 +2916,11 @@ merge(Compressor.prototype, {
} else if (node instanceof AST_ObjectIdentity) {
value = node;
}
if (value) lvalues.add(node.name, is_modified(compressor, tw, node, value, 0));
if (find_arguments && node instanceof AST_Sub) {
if (value) {
lvalues.add(node.name, is_modified(compressor, tw, node, value, 0));
} else if (node instanceof AST_Lambda) {
if (!(tw.find_parent(AST_Call) || tw.find_parent(AST_Scope))) return true;
} else if (find_arguments && node instanceof AST_Sub) {
scope.each_argname(function(argname) {
if (!compressor.option("reduce_vars") || argname.definition().assignments) {
if (!argname.definition().fixed) well_defined = false;
@@ -3023,7 +3027,10 @@ merge(Compressor.prototype, {
return false;
}
var def = lhs.definition();
return def.references.length - def.replaced == referenced;
if (def.references.length - def.replaced == referenced) return true;
return def.fixed && lhs.fixed && def.references.filter(function(ref) {
return ref.fixed === lhs.fixed;
}).length == referenced;
}
function symbol_in_lvalues(sym, parent) {