chrome-bookmarklet-ide icon indicating copy to clipboard operation
chrome-bookmarklet-ide copied to clipboard

Comments breaking code

Open victornpb opened this issue 8 years ago • 2 comments

I know that bookmarklets are supposed to be single line, I have a code that have single line comments and it result in broken syntax.

if(true){ //hello
    alert(1)
}
if(true){ //hello alert(1) }  (Syntax error)

I suggest wrapping single line comments with multiline comments like:

/*//hello*/

victornpb avatar Dec 04 '17 21:12 victornpb

good idea.. i wonder if this is something that the user should do though... if the user puts:

if (true) { // hello
  
}

and the software changes it to

if (true) { /* hello */

}

i think that's kind of breaking what the user is expecting. not sure, but i think this might be a wont-fix.

What do you think, @victornpb ?

ddavison avatar Dec 04 '17 22:12 ddavison

Sorry for replying late, what i suggested not was replacing it but rather wrapping it so it could be unwrapped in edit mode.

You may need to add some symbols in order to correctly "parse" it with a regular expression.

//hello
/*//hello*/
replace(/\/\/(.*)/,'\/\*//$1*\\') 


/*//hello*/
//hello
replace(/\/\*\/\/(.*)\*\//g, '\/\/$1')


victornpb avatar Jan 16 '18 03:01 victornpb