4

When minifying JavaScript in the handy tool by Google called Closure Compiler it gives the following error (and doesn't minify a thing):

Number of errors: 1 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 389 character 1 in all.js

theme : 'default', // The theme of the slider (default, theme1, theme2, t...

Where is the fault and what needs to be changed to fix the error?

$(window).load(function(){
jQuery('#slider1').autoSlider({
    theme               : 'default',    // The theme of the slider (default, theme1, theme2, theme3)
    width               : '960',    // The width of the slider, 100% for auto full width, set to 0 it will take the width of the largest image
    autoHidePlayBtn     : true,     //

2 Answers 2

10

The fault (for fear of simply rewording what the Closure Compiler error says) is that IE8 and below cannot parse object literals and array literals which have a trailing comma.

var obj = {
    a: 1,
    b: 2, // trailing comma is bad!
};

... vs...

var obj = {
    a: 1,
    b: 2 // no trailing comma!
};

The fix is to remove the trailing comma.

Sign up to request clarification or add additional context in comments.

2 Comments

To add - EcmaScript version 3 (which is what IE8 and lower obeys, as well as older Firefox, and other old browsers) does not allow trailing commas in arrays and ES5 (the current specification) does.
Actually ES3 does allow trailing commas in arrays, and the syntax for array literals did not change at all from ES3 to ES5. Rather ES5 adds the line "If an element is elided at the end of an array, that element does not contribute to the length of the Array.". IE8 was actually properly following the spec with array literals, it was just counter intuitive
2

You have three options to get rid of this warning:

  1. Remove the trailing comma
  2. Change the compilation mode (using language_in) to later compilation mode such as ECMASCRTIPT6 or ECMASCRIPT6_STRICT (The trailing comma was standardized in EcmaScript 5).
  3. Change the compiler's warning level for the "es3" diagnostic group to "OFF".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.