comment causes previous line to have space

Paul Tunison avatarPaul Tunison created an issue

I noticed this when your own tests were failing. The "testIgnoreComment", "testNoBracesWithComment" and "testSingleComment" test cases in the test.py file reveal a trailing space on the line before the comment occurred, or the line that an in-line comment occurred. Basically, these test cases are causing both do_space and do_newline variables to be True, causing ' \n' to be written instead of just '\n'. Protecting that write such that only one of the two actions is performed, giving priotity to the new-line, solves this problem for me:

... (line 179)
            else:
                if do_newline:
                    write('\n')
                elif do_space:
                    write(' ')
                do_space = False
                do_newline = False
                write(next1)
... (line 188)

Original Code:

... (line 179)
            else:
                if do_space:
                    do_space = False
                    write(' ')
                if do_newline:
                    write('\n')
                    do_newline = False
                write(next1)
... (line 188)

Comments (5)

  1. Paul Tunison

    I'm working on CentOS 6.4 using Python 2.7.5. I'm running tests via nosetests.

    I'm using jsmin as downloaded from https://pypi.python.org/pypi/jsmin. When I diff the files from the version that I downloaded with the current versions here, the __init__.py has no difference and is exactly the same, but the test.py file currently here (the one with all the passing tests) has extra white-space compared to the one I had downloaded. If I remove trailing white space from the test.py file, then the file that I downloaded and your current version are exact matches. The extra white-space in the current test.py is causing the tests to pass, hiding where extra spaces are injected into the minified text. Since there is a non-trivial amount of extra white-space that does not occur within raw-strings, I cannot tell which white-spaces are intentional and which are not.

    In particular, its the line ending white-space on lines 57, 132 and 170 that are causing the tests to pass vs. when they are not there. Removing these trailing spaces causes the three pertaining tests to now fail.

  2. Venelin Stoykov

    Today I upgraded to jsmin 2.0.4 and I also noticed this bug. When there is a inline comment it puts // on the same line but after that it puts a new line and the comment text became alone on a new line. By this this text is not commented any more and cause a javascript errors.

  3. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.