1

I'm use Google Closure Compiler first time and after compilation some js code compiler gives error

JSC_TRAILING_COMMA: Parse error. IE8 (and below) will parse trailing commas in array and object literals incorrectly

But my code my code is meant to recent browsers.

Is there any option for exclude compilation for IE8?

Taron Mehrabyan
  • 2,199
  • 2
  • 20
  • 27
  • So why it says IE8(and below)? it is working code – Taron Mehrabyan Feb 03 '14 at 09:03
  • I was wrong. ES5 [allows a trailing comma in a object literal](http://es5.github.io/#x11.1.5). Anyway, the simplest fix is to *remove* any such trailing comma from such object literals for compatibility with ES3-only implementations (ie. IE8). (Older versions of FF accepted the then-invalid ES3 grammar productions.) – user2864740 Feb 03 '14 at 09:04
  • 1
    If the google closure compiler does not show you the line, then use jslint or jshint with your code it should show you a line like e.g. `{key: value, ... , keyN:valueN,}` when you remove the last `,` then you won't have the `JSC_TRAILING_COMMA` error anymore. This last `,` will (no matter if _compiled_ or not) produces an error in IE. ([Internet Explorer, Closure Compiler and Trailing Commas](http://stackoverflow.com/q/11823162/1960455)) – t.niese Feb 03 '14 at 09:06

1 Answers1

1

If you don't need to support older IE's you can set the language mode to "ECMASCRIPT5" or "ECMASCRIPT5_STRICT", and you will no longer receive this warning.

https://code.google.com/p/closure-compiler/wiki/FAQ#I_get_a_"Trailing_comma_is_not_legal"_error._But_it_wo

Chad Killingsworth
  • 14,360
  • 2
  • 34
  • 57
John
  • 5,443
  • 15
  • 21