开发者

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

开发者 https://www.devze.com 2023-02-03 00:51 出处:网络
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 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?


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.


A semicolon might be encapsulated in a string. Adding a line break to the string would change the meaning of the javascript.


If the semicolon is inside of a string or a regex (such as var rex = /;/g; — it's only safe to insert a line break after the second semicolon), then yes, that would obviously be a problem. Otherwise, it's always safe to have a line break after a statement.


Admin or maybe developer needs to run this command on each VOB where artifact is stored (in context of desired VOB) (not 100% sure about the -supertype, "binary_file" might be better) (not 100% sure about the -mergetype, "copy" might be better!) (you can always change this later via -replace option)

cleartool mkeltype -nc -supertype text_file -manager z_whole_copy -mergetype auto text_file_minified

This can be used to correct files that failed trying to checkin. They have probably been created with a type of "text_file" individual lines of text_file types cannot exceed 8000 characters.

cleartool chtype -nc -force text_file_minified jquery-1.8.2.min.js

PUT this file on your desktop/dev machine where you checkin. Remove any leading spaces.

# AAA.magic
# This needs to copied to all developer desktops
# copy it next to default.magic (or cc.magic)
#   under ...\ClearCase\config\magic

# Leave these from the default.magic just in case
# files are processed in alphabetic order, hence the AAA prefix

# Check stat type
directory : -stat d ;
block_device : -stat b ;
char_device : -stat c ;
socket : -stat s ;
fifo : -stat f ;

# minified javascript and CSS
# some of these violate the 8000 character per line limit 
#  of clearcase text tools/type managers
# *.min.js
text_file_minified : -name "*.[mM][iI][nN].[jJ][sS]" ;
# *.min.css
text_file_minified : -name "*.[mM][iI][nN].[cS][sS][sS]" ;


A semi-colon in Javascript always determines the end of a code line.

Given this, it should always be safe to add a line break after a semi-colon unless that semi-colon is part of a string.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号