Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make collapse_vars consistent with toplevel #1608

Merged
merged 1 commit into from Mar 16, 2017

Conversation

alexlamsl
Copy link
Collaborator

fixes #1605

/cc @kzc

lib/compress.js Outdated
@@ -558,7 +559,8 @@ merge(Compressor.prototype, {

// Only interested in cases with just one reference to the variable.
var def = self.find_variable && self.find_variable(var_name);
if (!def || !def.references || def.references.length !== 1 || var_name == "arguments") {
if (!def || !def.references || def.references.length !== 1
|| var_name == "arguments" || !toplevel && def.global) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this code is correct, but could you please put unnecessary parens around (!toplevel && def.global) ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, I was wondering who put all those parentheses throughout the codebase 👻

No problem, consider it done 😉

Copy link
Contributor

Choose a reason for hiding this comment

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

I just find it easier to read.

I know, I know... Uglify devs should not need any whitespace and unnecessary parens. ;-)

}
input: {
function foo() {
return 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please define function foo as the following to show that collapse_vars works in functions regardless of the toplevel setting?

function foo(x){ var y = x; return y; }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

input: {
function foo() {
return 1;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please define function foo as the following to show that collapse_vars works in functions regardless of the toplevel setting?

function foo(x){ var y = x; return y; }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@kzc
Copy link
Contributor

kzc commented Mar 16, 2017

Thanks!

LGTM.

@alexlamsl alexlamsl merged commit 5ae04b3 into mishoo:master Mar 16, 2017
@alexlamsl alexlamsl deleted the issue-1605 branch March 16, 2017 05:22
@alexlamsl alexlamsl mentioned this pull request Mar 17, 2017
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.

Missing var statement for class definition
2 participants