在goog.base中抑制或解决编译器错误 [英] Suppressing or resolving compiler errors in goog.base

查看:66
本文介绍了在goog.base中抑制或解决编译器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的源代码上使用Closure Compiler,最近决定通过 - jscomp_warning = reportUnknownTypes 启用最严格的模式。唉,它在 goog.base 本身内引发了很多警告!我已经修复了我自己的代码中的所有问题,现在我正在寻找一种方法来解决/删除闭包库代码中的错误。

I use Closure Compiler on my sources and recently decided to enable the most strict mode via --jscomp_warning=reportUnknownTypes. Alas, it triggered a lot of warnings inside the goog.base itself! I've fixed all the problems in my own code and now I'm looking for a way to silence/remove errors in the closure library code.

我试图修复 base.js 中的错误但很快意识到这是不可行的。文件中大约有108个错误,在大多数情况下,它们是真正的错误,因为 goog.base 并不关心类型:它是通常的做法是定义类似 {?} {*}

I tried to fix errors in base.js but quickly realized it's unfeasible. There are approximately 108 errors in the file and in most cases they are real errors because of goog.base doesn't care much about types: it's a common practice there to define a type like {?} or {*}.

我还尝试使用 - warnings_whitelist_file 来消除我不关心的警告,但它也没有用。如有错误:

I also tried to use --warnings_whitelist_file to silence warnings I don't care about but it didn't work either. For an error:

.. \ js \ google\base.js:204:警告 - 无法确定此类型表达式
cur [part] = opt_object;
^

我在白名单文件中尝试了不同的表单,但没有一个有效:

I tried different forms in the whitelist file but none has worked:

.. \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\确定此表达式的类型
.. \\\ js \ google \ base.js:204警告 - 无法确定此表达式的类型
../js/google/base.js: 204无法确定此表达式的类型
../js/google/base.js:204警告 - 无法确定此表达式的类型
.. \ js \ google \ base .js:204警告 - 无法确定此表达式的类型
cur [part] = opt_object;

是否有人使用工作解决方案来启用此模式并且不会被来自闭包库本身的错误?

Does anybody have a working solution to have this mode enabled and not get spammed by the errors from the closure library itself?

我使用最新的Closure Compiler,它是:

版本:v20150315
建立于:2015/03/17 14:18

I use latest Closure Compiler which is: Version: v20150315 Built on: 2015/03/17 14:18

推荐答案

所以,我决定在 base.js 中使用静音警告。为此我调查了编译器源(感谢作者的开源),我发现标志描述与其实际效果不符。描述说:

So, I decided to go the path with silencing warnings in the base.js. For that I've investigated compiler sources (thanks to the authors it's open source) and I found out that flag description doesn't match its actual effect. The description says:

包含要抑制的警告的文件。每行的格式应为< file-name>:< line-number>? < warning-description>

但实际上这个警卫会拦截匹配的错误转换他们成警告。而且,行号完全被忽略。我认为这种行为没有使用这个标志,但我认为作者有充分的理由以这种方式实现它。

But in fact this guard intercepts matching errors and converts them into warnings. Moreover, line numbers are completely ignored. I see no use of this flag with such behavior but I bet authors had a good reason to implement it this way.

无论如何,我从主分支和固定标志分叉行为。现在匹配的错误和警告实际上已被抑制(沉默)。现在在匹配中考虑行号。

Anyways, I forked from the main branch and fixed flag's behavior. Now matched errors and warnings are actually suppressed (silenced). Line numbers are now considered in the matching.

白名单文件的语法与错误/警告输出非常相似。例如,如果您收到如下错误(或警告):

Syntax of the whitelist file is very similar to the error/warning output. For example if you get error (or warning) like this:

.. \ js \ google \ base.js:120:错误 - 无法确定此表达式的类型
if(goog.getObjectByName(namespace)){
^

然后白名单文件中的相关记录将是:

Then the relevant record in the whitelist file will be:

.. \ js \ google \ base.js:120不能确定此表达式的类型

您可以使用但只有第一行用于匹配。

You may add content of multiline errors as comments preceding them with # but only first line will be used for matching.

如果这是你需要的,你可以通过以下两种方式之一获得二进制:

If this is what you need you may obtain the binary via one of the two ways:

  • Get the patched sources and build the binary yourself: ihsoft/closure-compiler - Wiki
  • Get the pre-built compiler binary: ihsoft/closure-compiler - Release v1.0-tuned

这篇关于在goog.base中抑制或解决编译器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆