Search code examples
javascriptsyntaxnewlineclearcase

Is it always safe to insert a linebreak after a semicolon?


I am having an issue checking in a minified JavaScript file into Clearcase. The file in question is a single line, well over the 8000 character limit that Clearcase imposes.

I know that JavaScript interpreters do some tricky things inserting semicolons at linebreaks, but I am wondering if it should always be safe to add a linebreak after a semicolon. Is it possible that doing so would change the meaning of the JavaScript code?


Solution

  • To answer your immediate question: yes, you can add line breaks after a semicolon that ends a statement. There may be other uses of semicolons (e.g. inside a string or regex) in the file, and you shouldn't touch those.

    I have another question for you: Why are you checking in a minified JavaScript file? I would think it's better to check in the original verbose JavaScript source. Plus, version control systems aren't effective in general for files of only one line. If you are already checking in the original JavaScript, you now have to maintain consistency between the two files (i.e. when you change one you must refresh the other). I suggest checking in a script that will minify the original when you deploy it instead of keeping the minified version in Clearcase.