Patrick Galbraith

Web developer - Adelaide, Australia

IE Conditional Compilation and @TODO

Spoiler: they are not friends

So today I was working on fixing compatibility issues in Internet Explorer on a new project when I ran into an error like this on IE versions 8 to 10.

SCRIPT1004: Expected ';'
File: example.js, Line: 9, Column: 35

And the line it was pointing to looked like this.

var test = 1; //@todo: add new feature

Well it turns out that if conditional compilation (http://msdn.microsoft.com/en-us/library/ie/121hztk3(v=vs.94).aspx) is turned on using /*@cc_on @*/ in any script. Using the @ symbol anywhere at the start of a comment causes Internet Explorer to throw a syntax error.

The minimum reproducable test case is:

/*@cc_on @*/
var test = 1; //@todo: add new feature

Which can be fixed by putting a space in front of the @ symbol like this.

/*@cc_on @*/
var test = 1; // @todo: add new feature

This becomes an issue in larger codebases where you cannot know if other scripts have turned conditional compilation on at all. As far as I know there isn't a workaround. However you can show a console message warning that conditional compilation is on like this.

/*@if (@_jscript) if ('console' in self && 'log' in console) console.log('Conditional compilation is turned on!'); @end @*/

Keep in mind however that a syntax error caused by the @ symbol will trigger before the above runs.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>