javascript 如何为 Closure 编译器设置 language_in 选项?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13261325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I set the language_in option for the Closure compiler?
提问by Elisabeth
I need to set the language_in option on the Closure compiler to prevent the IE8 parse error:
我需要在 Closure 编译器上设置 language_in 选项以防止 IE8 解析错误:
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.
错误 - 解析错误。IE8(及以下)将错误地解析数组和对象文字中的尾随逗号。如果您的目标是较新版本的 JS,请设置适当的 language_in 选项。
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.
我确实在闭包组中找到了与此相关的帖子,但是,该选项是直接在 java 编译器上设置的,而不是通过其中一个构建脚本设置的。我需要能够在构建脚本上设置它。
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.
我正在查看closure/bin/build/ 中的脚本,那里有几个。我尝试将选项添加到闭包构建器,但失败了。
Can someone direct me about how to set this option correctly?
有人可以指导我如何正确设置此选项吗?
Thank you.
谢谢你。
回答by Christopher Peisert
Run the Closure Compiler Applicationwith the --help
flag to see a description of each flag.
运行带有标志的Closure Compiler Application--help
以查看每个标志的描述。
java -jar compiler.jar --help
CommandLineRunnerdefines the set of allowed values for --language_in
:
CommandLineRunner定义了一组允许的值--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
--language_in
设置输入源符合的语言规范。
选项:ECMASCRIPT3、ECMASCRIPT5、ECMASCRIPT5_STRICT、ECMASCRIPT6_TYPED(实验性)、ECMASCRIPT_2015、ECMASCRIPT_2016、ECMASCRIPT_2017、ECMASCRIPT_NEXT
The LanguageMode enumhas a bit more detail about these values.
该LanguageMode枚举了有关这些值的一些详细信息。
Using Closure Builder, the --language_in
flag would be passed as an argument to--compiler_flags
as in:
使用Closure Builder,该--language_in
标志将作为参数传递给--compiler_flags
如下:
--compiler_flags="--language_in=ECMASCRIPT5"