【发布时间】:2015-04-09 04:49:02
【问题描述】:
我在源代码上使用 Closure Compiler,最近决定通过 --jscomp_warning=reportUnknownTypes 启用最严格的模式。唉,它在goog.base 本身内部触发了很多警告!我已经解决了我自己代码中的所有问题,现在我正在寻找一种方法来消除/删除闭包库代码中的错误。
我尝试修复 base.js 中的错误,但很快意识到这是不可行的。文件中大约有 108 个错误,在大多数情况下它们是真正的错误,因为 goog.base 不太关心类型:在那里定义像 {?} 或{*}.
我还尝试使用--warnings_whitelist_file 来消除我不关心的警告,但它也不起作用。对于错误:
..\js\google\base.js:204: WARNING - could not determine the type of this expression
cur[part] = opt_object;
^
我在白名单文件中尝试了不同的形式,但都没有奏效:
..\\js\\google\\base.js:204 could not determine the type of this expression
..\\js\\google\\base.js:204 WARNING - could not determine the type of this expression
..\js\google\base.js:204 could not determine the type of this expression
..\js\google\base.js:204 WARNING - could not determine the type of this expression
../js/google/base.js:204 could not determine the type of this expression
../js/google/base.js:204 WARNING - could not determine the type of this expression
..\js\google\base.js:204 WARNING - could not determine the type of this expression
cur[part] = opt_object;
是否有人有可行的解决方案来启用此模式,并且不会因闭包库本身的错误而收到垃圾邮件?
我使用最新的闭包编译器,它是:
Version: v20150315
Built on: 2015/03/17 14:18
【问题讨论】:
-
reportUnknownTypes非常垃圾,一般不推荐。总有一天我们会转而使用github.com/google/closure-compiler/issues/152(实现该检查的更细微的版本),我们可能会建议打开它。 -
好吧,它是垃圾邮件,但是一旦我修复了所有错误(虽然有时是黑客),代码变得更加正确。几个未被注意到的错误是固定的。所以,尽管有很多麻烦,但它是一种非常有用的模式,我想继续使用它。
-
顺便说一句,我是 githab 上的“ihsoft” :) 最近编译器的错误来自我。
-
如果您使用 Java API 运行编译器,则可以配置警告保护以不显示警告。还应该注意的是,虽然类型值是未知的,但它们应该是未知的,更好的检查不会警告声明为未知的值。作为一致性框架的一部分,有一个更有限但仍然非常有用的检查(未知的 this 检查和未知的类属性检查)
标签: javascript google-closure-compiler google-closure