fix function name eliminiation (#1576)

Function expression can be assigned to a variable and be given a name. Ensure function name is the reduced variable before clearing it out.

fixes #1573
fixes #1575
This commit is contained in:
Alex Lam S.L
2017-03-08 12:39:57 +08:00
committed by GitHub
parent 3ee55748d4
commit c7cdcf06a6
2 changed files with 24 additions and 1 deletions

View File

@@ -2611,7 +2611,8 @@ merge(Compressor.prototype, {
if (compressor.option("unused")
&& def.references.length == 1
&& compressor.find_parent(AST_Scope) === def.scope) {
if (!compressor.option("keep_fnames")) {
if (!compressor.option("keep_fnames")
&& exp.name && exp.name.definition() === def) {
exp.name = null;
}
self.expression = exp;

View File

@@ -1122,3 +1122,25 @@ defun_label: {
}();
}
}
double_reference: {
options = {
reduce_vars: true,
unused: true,
}
input: {
function f() {
var g = function g() {
g();
};
g();
}
}
expect: {
function f() {
(function g() {
g();
})();
}
}
}