I have the following javascript snippet to detect if a browser is IE 6 - 11:
var isIE = /*@cc_on!@*/false || !!document.documentMode;
I copied this from an excellent answer on SO here. However when i go to minify the script with yuicompressor, it breaks it with the following errors:
[ERROR] in utils.js
349:33:missing ; before statement
[ERROR] in utils.js
1:0:Compilation produced 1 syntax errors.
org.mozilla.javascript.EvaluatorException: Compilation produced 1 syntax errors.
at com.yahoo.platform.yui.compressor.YUICompressor$1.runtimeError(YUICompressor.java:172)
at org.mozilla.javascript.Parser.parse(Parser.java:396)
at org.mozilla.javascript.Parser.parse(Parser.java:340)
at com.yahoo.platform.yui.compressor.JavaScriptCompressor.parse(JavaScriptCompressor.java:315)
at com.yahoo.platform.yui.compressor.JavaScriptCompressor.<init>(JavaScriptCompressor.java:536)
at com.yahoo.platform.yui.compressor.YUICompressor.main(YUICompressor.java:147)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.yahoo.platform.yui.compressor.Bootstrap.main(Bootstrap.java:21)
I read up on yuicompressor and found that it can preserve javascript block comments when they are like so: /*! comment */
, however changing the snippet to the following does not fix it:
var isIE = /*!@cc_on!@*/false || !!document.documentMode;
The error messages are still the same. And I also wonder if this would break the conditional compilation? All the examples of conditional compilation open a comment like so /*@
and close it like so: @*/
which makes me think that conditional compilation only works with this combination of comment symbols.
Does anybody know how I can get this working? Other solutions which maintain the same functionality and pass correctly through yuicompressor are also acceptable as an answer here.