fix function name eliminiation#1576
Conversation
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 mishoo#1573 fixes mishoo#1575
| if (!compressor.option("keep_fnames")) { | ||
| if (!compressor.option("keep_fnames") | ||
| && exp.name && exp.name.definition() === def) { | ||
| exp.name = null; |
There was a problem hiding this comment.
Why bother with this here when it will be cleaned up later in one place?
There was a problem hiding this comment.
It didn't work with drop_unused() before, hence I put the extra code there back then.
But I agree, let me investigate and fix this properly.
There was a problem hiding this comment.
Ah, it's because the original copy of the function is still around and waiting for elimination by drop_unused(), so it can't tell the function is no longer referenced afterwards.
I'll think about this and give it a proper fix this afternoon.
There was a problem hiding this comment.
What's wrong with #1575 (comment) ?
$ echo 'function f(){x} var a=f(b);x(a);' | bin/uglifyjs -c toplevel
WARN: Dropping unused function f [-:1,9]
var a=function f(){x}(b);x(a);
The (now unused) function name is not eliminated.
There was a problem hiding this comment.
I think it's better to get this fix merged and a new release made. You can tweak it later.
There was a problem hiding this comment.
Fair point. Will do.
|
confirmed that this fixes #1573! thanks @alexlamsl! |
|
Doc update required. Might as well add it to this PR. |
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