Skip to content

fix function name eliminiation#1576

Merged
alexlamsl merged 1 commit into
mishoo:masterfrom
alexlamsl:issue-1573
Mar 8, 2017
Merged

fix function name eliminiation#1576
alexlamsl merged 1 commit into
mishoo:masterfrom
alexlamsl:issue-1573

Conversation

@alexlamsl

Copy link
Copy Markdown
Collaborator

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

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
Comment thread lib/compress.js
if (!compressor.option("keep_fnames")) {
if (!compressor.option("keep_fnames")
&& exp.name && exp.name.definition() === def) {
exp.name = null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why bother with this here when it will be cleaned up later in one place?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's wrong with #1575 (comment) ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to get this fix merged and a new release made. You can tweak it later.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. Will do.

@brentvatne

Copy link
Copy Markdown

confirmed that this fixes #1573! thanks @alexlamsl!

@kzc

kzc commented Mar 8, 2017

Copy link
Copy Markdown
Contributor

Doc update required. Might as well add it to this PR.

#1573 (comment)

@alexlamsl
alexlamsl merged commit c7cdcf0 into mishoo:master Mar 8, 2017
@alexlamsl
alexlamsl deleted the issue-1573 branch March 8, 2017 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2.8.8 can break recursive function calls v2.8.8 breaks React Native

3 participants