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

Fix issue with reduce_vars #363

Merged
merged 2 commits into from
Jul 31, 2019
Merged

Fix issue with reduce_vars #363

merged 2 commits into from
Jul 31, 2019

Conversation

L2jLiga
Copy link
Contributor

@L2jLiga L2jLiga commented Jun 6, 2019

Fixes #354
Fixes #294
Fixes #308

lib/compress/index.js Outdated Show resolved Hide resolved
@L2jLiga L2jLiga changed the title Fix issue with immediately invoked function and variable-name collision Fix issue with collapse_vars Jun 8, 2019
@L2jLiga L2jLiga changed the title Fix issue with collapse_vars Fix issue with reduce_vars Jun 14, 2019
@L2jLiga
Copy link
Contributor Author

L2jLiga commented Jul 7, 2019

@fabiosantoscode any updates?

@fabiosantoscode
Copy link
Collaborator

I'm very concerned about this: https://github.com/terser-js/terser/pull/363/files#diff-7a02108b11616cdd07d36b9a138a71cbR1290

undefined_variable++ is NaN, why is there even a zero there?

lib/compress/index.js Outdated Show resolved Hide resolved
@fabiosantoscode
Copy link
Collaborator

Nevermind the NaN thing and the comment @L2jLiga, I'm missing the fact that this is not used only in the ++ operation.

This PR looks great. Let me investigate what could be the impact of this transformation to a 0 to ensure everything is going to be fine. Don't want to break anything anymore :D

@L2jLiga
Copy link
Contributor Author

L2jLiga commented Jul 28, 2019

I think impact will be suboptimal result for some cases, so I suggest to create an issue to not forget to investigate/fix this

@fabiosantoscode
Copy link
Collaborator

@L2jLiga I've just had a long look. The impact isn't relevant enough that I care about it.

The 0; would only be output when the variable is an AST_Unary which is unused, which can really only happen if its parent is a single-expression statement. However, I don't want to increase the complexity of terser for a 2 byte reduction which would only take place if someone uses an unary operation on an unused variable, which is a pretty silly thing to do by hand.

Please remove the TODO comment and this PR can go in. Awesome work!

Andrey Chalkin added 2 commits July 29, 2019 05:04
safe_to_assign function call was changed for AST_Assignment in 6ccab38 but method was not changed.
@L2jLiga
Copy link
Contributor Author

L2jLiga commented Jul 28, 2019

TODO comment removed and PR rebased on top of master :)

@L2jLiga
Copy link
Contributor Author

L2jLiga commented Jul 31, 2019

@fabiosantoscode let's land this

@fabiosantoscode fabiosantoscode merged commit 3c80627 into terser:master Jul 31, 2019
@fabiosantoscode
Copy link
Collaborator

Right. I forgot to merge. But I didn't want to ship because I'm working and if something breaks I can't handle it. Starting tomorrow I'm on vacation. Kind of. And I can ship the new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants