19

I need to set the language_in option on the Closure compiler to prevent the IE8 parse error:

ERROR - 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.

I did find a post in the closure group relating to this, however, the option is set directly on the java compiler, rather than through one of the build scripts. I need to be able to set it on a build script.

I'm looking at the scripts in closure/bin/build/ and there are several there. I tried adding the option to closure builder, but it failed.

Can someone direct me about how to set this option correctly?

Thank you.

Andreas Louv
  • 46,145
  • 13
  • 104
  • 123
Elisabeth
  • 2,972
  • 6
  • 35
  • 39
  • In case you want to add option when compiling through wro4j (Maven) see: https://stackoverflow.com/questions/13872186/ecmascript-5-with-wro4j-and-google-closure-compiler/48442401#48442401 – Nux Jan 25 '18 at 12:45

1 Answers1

28

Run the Closure Compiler Application with the --help flag to see a description of each flag.

java -jar compiler.jar --help

CommandLineRunner defines the set of allowed values for --language_in:

--language_in
Sets what language spec that input sources conform.
Options: ECMASCRIPT3, ECMASCRIPT5, ECMASCRIPT5_STRICT, ECMASCRIPT6_TYPED (experimental), ECMASCRIPT_2015, ECMASCRIPT_2016, ECMASCRIPT_2017, ECMASCRIPT_NEXT

The LanguageMode enum has a bit more detail about these values.

Using Closure Builder, the --language_in flag would be passed as an argument to
--compiler_flags as in:

--compiler_flags="--language_in=ECMASCRIPT5"
Mike Samuel
  • 118,113
  • 30
  • 216
  • 245
Christopher Peisert
  • 21,862
  • 3
  • 86
  • 117