extend reduce_funcs to cover cross-scope substitutions (#2469)

fixes #2468
This commit is contained in:
Alex Lam S.L
2017-11-11 15:30:17 +08:00
committed by GitHub
parent 3c74047368
commit cda27b0970
2 changed files with 208 additions and 6 deletions

View File

@@ -4256,10 +4256,11 @@ merge(Compressor.prototype, {
var fixed = self.fixed_value();
if (fixed instanceof AST_Defun) {
d.fixed = fixed = make_node(AST_Function, fixed, fixed);
if (!compressor.option("reduce_funcs")) d.single_use = false;
}
if (d.single_use && fixed instanceof AST_Function) {
if (d.escaped && d.scope !== self.scope || recursive_ref(compressor, d)) {
if (!compressor.option("reduce_funcs") && d.scope !== self.scope) {
d.single_use = false;
} else if (d.escaped && d.scope !== self.scope || recursive_ref(compressor, d)) {
d.single_use = false;
} else if (d.scope !== self.scope || d.orig[0] instanceof AST_SymbolFunarg) {
d.single_use = fixed.is_constant_expression(self.scope);