-2

Wrote a script "LC.sh" to Download and compile a lambda Calculator to Javascript. Here's the relevant part of the script:

[ ! -f ./compiler-latest.zip ] && echo "Downloading" && \
curl -R -O -L https://dl.google.com/closure-compiler/compiler-latest.zip

[ ! -f ./uni.c ] && echo "Downloading" && \
curl -R -O -L http://tromp.github.io/cl/uni.c

[ ! -f ./compiler.jar ] && echo "Decompressing" && \
unzip  compiler-latest.zip compiler.jar

[ ! -f ./LC.js ] && echo "Compiling" && \
emcc -DM=999999 -m32 -std=c99 uni.c -o LC.js

[ ! -f ./LC-min.js ] && echo "Minifying" && \
java -jar compiler.jar --js LC.js --js_output_file LC-min.js

produces the following 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.

Which is overcome by simply deleting the trailing commas and running the script again. Since I don't want others to encounter this, how can I fix this automatically with no manual intervention?

GlassGhost
  • 16,906
  • 5
  • 32
  • 45
  • If you're targetting Internet Explorer 9 and up you can run the google closure compiler with the `--jscomp_warning internetExplorerChecks` flag to turn this error into a warning. – yvesmancera Aug 07 '15 at 23:23
  • You can also simply run closure-compiler with the `--language_in=ECMASCRIPT5` and this is no longer an error. – Chad Killingsworth Aug 08 '15 at 01:17
  • @ChadKillingsworth Your comment solved my problem, please submit it as an answer so I can mark it as accepted. – GlassGhost Aug 08 '15 at 14:36

1 Answers1

1

The behavior of trailing commas is undefined in ECMAScript 3 and produced different result in Internet Explorer. For this reason, closure-compiler flags trailing commas as an error when the input language is set at ECMAScript 3 (which is currently the default).

If you are targeting only ECMAScript 5 compatible browsers (IE9+), then this is not an error.

To specify ECMAScript 5, use the --language_in=ECMASCRTIP5 flag.

Community
  • 1
  • 1
Chad Killingsworth
  • 14,360
  • 2
  • 34
  • 57