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

Replace newlines with semicolons wherever possible? (feature request) #46

Closed
IamMusavaRibica opened this issue Mar 27, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@IamMusavaRibica
Copy link

IamMusavaRibica commented Mar 27, 2022

Hello!

So I noticed that python-minifier, when for example encounters a builtin function used multiple times, assigns it to a variable at the very beginning: E=print
However, when it does so multiple times, they are put each in their own line.
On Windows, a new line consists of a carriage return and line break. It is 2 bytes on its own.
Using a semicolon would take only 1 byte.

How would one go about making this change?
I would make a pull request myself if I find any time to do it myself

I opened this issue to discuss, and point out possible drawbacks of this

(I know that by default it inserts only LINE FEED character, but when porting code across multiple machines this might or might not break?)

@dflook
Copy link
Owner

dflook commented Mar 27, 2022

Hi @IamMusavaRibica

Python itself doesn't care what the line endings are, as long as it's consistent throughout a file. As you said, python-minifier only outputs a linefeed character for newlines.

I haven't ever tested on windows 😬, but I don't think there is any chance of breakage as long as the output file isn't changed to insert a carriage return. I wouldn't recommend manually editing the output on any platform, but I would hope any windows editors follow the newline convention in the file. Even if it doesn't, as long as it replaces all newlines with CRLF it shouldn't break anything.

The idea of using semicolons when possible also came up in #25, for a slightly different reason.

If think it would be good to add a --prefer-semicolons or similar argument to enable this.
A PR would be welcome. It would be a fairly small change but testing can take a long time, so it may take a while to get merged.

@dflook dflook added the enhancement New feature or request label Mar 27, 2022
@IamMusavaRibica
Copy link
Author

Since python-minifier already uglifies the code, I don't see a reason why would one ever want improved readability by using line breaks instead of semicolons. Sure it is sometimes inevitable to use a linebreak though. I'll see what I can do about it in the upcoming days

@IamMusavaRibica
Copy link
Author

I am going to remember this issue and start working on a PR in about a month, I'll close this for now. Thank you once again for your response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants