Given something like
var obj = {
foo: function(){
try{
doSomething();
}catch(ex){
//@TODO - report error
}
}
}
MSIE 8 would throw up a "Missing semi-colon on line #" which was where the @TODO was.
After I sed'd the dozens of @TODO's to be !TODO, MSIE was able to properly parse the script and life went on. Am I missing something here, does MSIE use some sort of non-standard mechanism like //@PRAGMA ?
Googling for @TODO or //@ didn't bring up anything useful.
Given something like
var obj = {
foo: function(){
try{
doSomething();
}catch(ex){
//@TODO - report error
}
}
}
MSIE 8 would throw up a "Missing semi-colon on line #" which was where the @TODO was.
After I sed'd the dozens of @TODO's to be !TODO, MSIE was able to properly parse the script and life went on. Am I missing something here, does MSIE use some sort of non-standard mechanism like //@PRAGMA ?
Googling for @TODO or //@ didn't bring up anything useful.
Share Improve this question edited Sep 5, 2011 at 15:14 genesis 51k20 gold badges98 silver badges126 bronze badges asked Jun 22, 2010 at 9:22 DavidDavid 18.3k10 gold badges73 silver badges100 bronze badges 3- Doesn't happen on my copy of IE8. – T.J. Crowder Commented Jun 22, 2010 at 9:39
-
T.J. Crowder: It will if you put
/*@cc_on @*/
above the code. – Tim Down Commented Jun 22, 2010 at 9:43 - I had a thought yesterday. If this flag is initiated by javascript and stays active for the ENTIRE scope; that means for a wordpress page with dozens of third party scripts, one script could initiate it and all scripts would get sucked into the same behavior.... wow. – David Commented Aug 5, 2010 at 14:48
3 Answers
Reset to default 9This is to do with conditional pilation, an IE-only invention for varying JScript (IE's name for their flavour of ECMAScript) pilation based on information about the browser and environment. The syntax involves the @
symbol followed by a string to make up a variable, directive or statement. In this case, the presence of @TODO
directly after the start of a ment is causing the ment text to be interpreted as a conditional pilation statement, with @TODO
being a conditional pilation variable (with a value of NaN
: see http://msdn.microsoft./en-us/library/k0h7dyd7%28v=VS.80%29.aspx).
Conditional pilation statements are generally contained within JavaScript ments: these are there to prevent other browsers from attempting to interpret the code but are not in fact required to trigger conditional pilation. The MSDN documentation is here:
http://msdn.microsoft./en-us/library/ahx1z4fs%28v=VS.80%29.aspx
This feature is only enabled for code that appears after conditional pilation is enabled, which is achieved with
/*@cc_on @*/
Therefore if you can find this line and remove it then your //@TODO - report error
will be fine as it is. However, some of your code may rely on conditional pilation so this may not be an option. A workaround is to insert a space between the start of the ment (either //
or /*
) and the @
symbol:
// @TODO - report error
Microsoft's documentation is not clear enough to know why this works, since conditional pilation variables also work outside ments:
// The following works in IE:
/*@cc_on @*/
var j = @_jscript_build;
alert(j);
Therefore the safest option would be to avoid use of @TODO
altogether.
The ment+@ syntax is used for conditionnal pilation in Internet Explorer. See http://www.javascriptkit./javatutors/conditionalpile.shtml
I remembered seeing a post like this on our forums, seems it gets interpreted by JScript:
http://www.sencha./forum/showthread.php?92186-FIXED-579-Comment-line-leads-to-IE7-error&highlight=ment