Why is this javascript snippet triggering "Unexpected token ILLEGAL"? - javascript

One line of the minified google-code-prettify javascript lib triggers "Unexpected token ILLEGAL". If I remove it the lib works fine. I tried to remove special chars, expecting encoding to be the code but it seems it's not.
PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\r \xa0\u2028\u2029]+/,null,"\t\n\r Â\xa0

"],["str",/^(?:["\u201c\u201d](?:[^"\u201c\u201d]|["\u201c\u201d]{2})(?:["\u201c\u201d]c|$)|["\u201c\u201d](?:[^"\u201c\u201d]|["\u201c\u201d]{2})*(?:["\u201c\u201d]|$))/i,null,'"“â€'],["com",/^['\u2018\u2019].*/,null,"'‘’"]],[["kwd",/^(?:addhandler|addressof|alias|and|andalso|ansi|as|assembly|auto|boolean|byref|byte|byval|call|case|catch|cbool|cbyte|cchar|cdate|cdbl|cdec|char|cint|class|clng|cobj|const|cshort|csng|cstr|ctype|date|decimal|declare|default|delegate|dim|directcast|do|double|each|else|elseif|end|endif|enum|erase|error|event|exit|finally|for|friend|function|get|gettype|gosub|goto|handles|if|implements|imports|in|inherits|integer|interface|is|let|lib|like|long|loop|me|mod|module|mustinherit|mustoverride|mybase|myclass|namespace|new|next|not|notinheritable|notoverridable|object|on|option|optional|or|orelse|overloads|overridable|overrides|paramarray|preserve|private|property|protected|public|raiseevent|readonly|redim|removehandler|resume|return|select|set|shadows|shared|short|single|static|step|stop|string|structure|sub|synclock|then|throw|to|try|typeof|unicode|until|variant|wend|when|while|with|withevents|writeonly|xor|endif|gosub|let|variant|wend)\b/i,null],["com",/^rem.*/i],["lit",/^(?:true\b|false\b|nothing\b|\d+(?:e[+-]?\d+[dfr]?|[dfilrs])?|(?:&h[\da-f]+|&o[0-7]+)[ils]?|\d*\.\d+(?:e[+-]?\d+)?[dfr]?|#\s+(?:\d+[/-]\d+[/-]\d+(?:\s+\d+:\d+(?::\d+)?(\s*(?:am|pm))?)?|\d+:\d+(?::\d+)?(\s*(?:am|pm))?)\s+#)/i],["pln",/^(?:(?:[a-z]|_\w)\w*|\[(?:[a-z]|_\w)\w*])/i],["pun",/^[^\w\t\n\r "'[\]\xa0\u2018\u2019\u201c\u201d\u2028\u2029]+/],["pun",/^(?:\[|])/]]),["vb","vbs"]);
I tried to change ["pun",/^(?:\[|])/]]) to ["pun",/^(?:\[|])/]) but no luck.
EDIT:
I could identify that the "\t\n\r Â\xa0

" is causin it, but I can't tell why.

This is most probably an encoding problem, because removing ¨â from "\t\n\r Â\xa0

" solves the problem. Be removing one of the 2 characters won't.

Related

how to debug line break issues with javascript

I'm maintaining this website that accepts multi-line inputs from user and sends the data via JSON. line break \n are decoded and encoded properly but somehow the \r chars are not accepted on the server side and I have the feeling I would need to escape them prior to sending them over. Before making the fix, I want to try to reproduce the issue but I can't find a way to do it !!!!
Do you have any recommendations?
EDIT after more investigation, it turns out that the issue is in IE only ( as in the \r chars get added when copying/pasting to the text input). Hijacking the text area did not change anything in FF or chrome and doing a data.description.replace("\r","") did not solve the issue either. Still poking around.
if you just want to reproduce the error, just add some js to populate the textarea:
document.getElementById('textarea-id').value = 'test\r\ntest';
Chrome's Developer Tool's Javascript Console lets you send JSON to your server using friendly jQuery/MooTools/Protoype syntax

IE not loading page with Javascript and Raphael

I'm testing out a website that runs fine on Firefox (Win/Mac), Chrome (Win/Mac) and Safari. I'm having difficulty with Internet Explorer unfortunately. I get the following error message:
SCRIPT65535: Unexpected call to method or property access.
raphael-min.js, line 8 character 64961
I've taken a look at the debug output which looks like just takes me to a part of the Raphel library:
c=a.getScreenCTM()||a.createSVGMatrix()
I've searched for this error message online, but I don't understand what solution is relevant to this case as I've no idea what is causing the problem. I am also using the jQuery library. Are there any tests that I can do that can give me more information about the source of the problem?
I just found how to patch this, in order to keep the compressed version of Raphael.
Replace (don't forget the coma):
c=a.getScreenCTM()||a.createSVGMatrix(),
By that (dont't forget the end space):
c;try{c=a.getScreenCTM()||a.createSVGMatrix()}catch(e){c=a.createSVGMatrix()};var
Works fine ! :)
Means :
c; : declaration of variable c, and stop the first instruction.
try{c=a.getScreenCTM()||a.createSVGMatrix()}catch(e){c=a.createSVGMatrix()}; : our instruction, surrounded by a try/catch, to avoid IE error
var + a space : (don't forget the space!) allow us to continue to declare variable
I found out that it's an issue with compression (of the js file). I had the exact same issue and I had been searching for a solution. Guess what? I tried it with the uncompressed Raphael file and voila! No more issues. Compressed file needs a tweak, it seems.

Chrome: Uncaught Syntax Error : Unexpected token

Page here
Seems like chrome is the only browser having problems with this bit of javascript. I have found that if I remove the '//' from the CDATA tags chrome will give me a line number for the error - line 48. I dont even know where start with this bug unfortunately. The code works as expected but it just takes a bit longer to load/parse with chrome.
I have tried to use script as an external file (float.js) but the error is the same. In production the code will need to be included in the html body though. Any suggestions?
Edit: It was an extension causing this error, is there any way to code against this?
it was the 'Smooth Gestures' extension. removing fixed

File Encoding - Mysterious "?" Mark and "ILLEGAL Token" Error Messages

Come across this once in awhile.
Unpacked a zip file sent to me by a coworker. Loaded it up on my tomcat server to find out that there's this weird question mark at the beginning of the included JS file, preventing the JS file from being included properly.
I resaved the HTML file and the JS as new files and made sure encoding was UTF-8 and the line breaks were UNIX style.
Now I see the "ILLEGAL Token" error in Chrome and FF. Any ideas why?
EDIT:
Adding JS that is causing the issue. Anything inherently wrong with this? Per a comment, I think the removal of BOM fixed the issue but still getting the "ILLEGAL Token" message.
if(typeof deconcept=="undefined"){var deconcept=new Object();}
Hard to say with much confidence, but weird characters at the start of text files are very often the Byte Order Mark (BOM). See http://en.wikipedia.org/wiki/Byte_Order_Mark. Some software handles them well, and you see nothing, other software doesn't handle them correctly and you see weird characters.

Why does jQuery 1.4.2 compressed have a syntax error?

I always have noticed this, including in versions before as well. About half way through jQuery's compressed version you'll see some regex:
[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^
The error appears to be at ['"]
I'm sure it's not really a syntax error, but all my code editors recognize it as one, which makes development a pain if I try to combine JavaScript files. Does anyone know what's going on here?
It's a character entity in a regular expression, as specified by the square brackets. There are no restrictions on quote characters in them. All that's going on is buggy syntax highlighting. Ask the developer of your editor.
your code editor sucks, this isnt a syntax error if its inside of a regex literal, which i suspect it is.
the code editor you use probably doesnt support regex literals properly, and that its a string , which would cause the error

Categories