Search code examples
javascriptinternet-explorer-8google-closure-compilerjshintgoogle-closure

JSC_TRAILING_COMMA: Parse error. IE8 (and below) - Can jshint warning me for left trailing comma?


Using Google Closure Compiler I get this error:

JSC_TRAILING_COMMA: Parse error. IE8 (and below) will parse trailing commas in array and object literals incorrectly. If you are targeting newer versions of JS, set the appropriate language_in option. at line 7 character 9
        },

for the following code:

App.prototype = {
    testA: function () {

    },
    testB: function () {

    },
};

I would like to know if jshint has some build-in option to detect tailing commas and show a warning message.


Solution

  • JSHint will warn you "Extra comma. (it breaks older versions of IE)" if you set the es3 option (in version 2.0.0 and later):

    /*jshint es3: true */
    var x = {
        prop1: 10,
        prop2: 20,
    };
    

    In older versions of JSHint you don't need to set the es3 option as it's the default. All versions of JSLint will also give a similar warning.