diff options
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js index f72972b1..9fdfc43a 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3596,13 +3596,17 @@ merge(Compressor.prototype, { } else if (compressor.option("functions") && def.value === def.name.fixed_value() && def.value instanceof AST_Function - && !def.value.name - && !def.value.variables.get(def.name.name) + && can_rename(def.value, def.name.name) && (!compressor.has_directive("use strict") || parent instanceof AST_Scope)) { compressor.warn("Declaring {name} as function [{file}:{line},{col}]", template(def.name)); var defun = make_node(AST_Defun, def, def.value); defun.name = make_node(AST_SymbolDefun, def.name, def.name); - def.name.scope.resolve().def_function(defun.name); + var name_def = def.name.scope.resolve().def_function(defun.name); + if (def.value.name) def.value.name.definition().references.forEach(function(ref) { + ref.name = name_def.name; + ref.thedef = name_def; + ref.reference({}); + }); body.push(defun); } else { if (side_effects.length > 0) { @@ -3633,6 +3637,11 @@ merge(Compressor.prototype, { } sym.eliminated++; } + + function can_rename(fn, name) { + var def = fn.variables.get(name); + return !def || fn.name && def === fn.name.definition(); + } }); if (head.length > 0 || tail.length > 0) { node.definitions = head.concat(tail); |