diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-11-09 23:30:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-09 23:30:00 +0800 |
commit | 1127a2caf305ad1df370c34faf7283e53423cc10 (patch) | |
tree | 863afaf693e2f5337849c46615927fd7cbcd3f25 /lib | |
parent | 246d9d4e83e857a26347944ada65fea95ad6381d (diff) | |
download | tracifyjs-1127a2caf305ad1df370c34faf7283e53423cc10.tar.gz tracifyjs-1127a2caf305ad1df370c34faf7283e53423cc10.zip |
fix multiple nested function substitutions (#2458)
fixes #2449
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/lib/compress.js b/lib/compress.js index e457d808..d915e23e 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -313,19 +313,14 @@ merge(Compressor.prototype, { if (node instanceof AST_SymbolRef) { var d = node.definition(); d.references.push(node); + var value; if (d.fixed === undefined || !safe_to_read(d) || d.single_use == "m") { d.fixed = false; } else if (d.fixed) { - var value = node.fixed_value(); + value = node.fixed_value(); if (value && ref_once(d)) { - if (value instanceof AST_Lambda) { - d.single_use = d.scope === node.scope - && !(d.orig[0] instanceof AST_SymbolFunarg) - || value.is_constant_expression(node.scope); - } else { - d.single_use = d.scope === node.scope - && value.is_constant_expression(); - } + d.single_use = value instanceof AST_Lambda + || d.scope === node.scope && value.is_constant_expression(); } else { d.single_use = false; } @@ -335,10 +330,9 @@ merge(Compressor.prototype, { } else { d.fixed = false; } - } else { - mark_escaped(d, node, value, 0); } } + mark_escaped(d, node, value, 0); } if (node instanceof AST_SymbolCatch) { node.definition().fixed = false; @@ -385,10 +379,7 @@ merge(Compressor.prototype, { d.fixed = node; loop_ids[d.id] = in_loop; mark(d, true); - if (ref_once(d)) { - d.single_use = d.scope === d.references[0].scope - || node.is_constant_expression(d.references[0].scope); - } + d.single_use = ref_once(d); } var save_ids = safe_ids; safe_ids = Object.create(null); @@ -2209,7 +2200,10 @@ merge(Compressor.prototype, { && !self.variables.has(def.name)) { if (scope) { var scope_def = scope.find_variable(node); - if (def.undeclared ? !scope_def : scope_def === def) return true; + if (def.undeclared ? !scope_def : scope_def === def) { + result = "f"; + return true; + } } result = false; } @@ -4256,11 +4250,20 @@ merge(Compressor.prototype, { if (fixed instanceof AST_Defun) { d.fixed = fixed = make_node(AST_Function, fixed, fixed); } - if (fixed - && d.single_use - && !(fixed instanceof AST_Function - && (d.escaped && d.scope !== self.scope - || recursive_ref(compressor, d)))) { + if (d.single_use && fixed instanceof AST_Function) { + 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); + if (d.single_use == "f") { + var scope = self.scope; + do { + if (scope.name) scope.name.definition().single_use = false; + } while (scope = scope.parent_scope); + } + } + } + if (d.single_use && fixed) { var value = fixed.optimize(compressor); return value === fixed ? fixed.clone(true) : value; } |