我正在编译文件并获得可运行的编译代码,但注释似乎被完全忽略了;没有警告没有错误。使用 calcdeps.py 通过以下命令编译我的代码:
set calc="D:\software\closure compiler\library\closure\bin\calcdeps.py"
c:\Python27\python.exe %calc% ^
--path D:\flex_sdk_4.6\projects\EnglishConverter\bin\js\ ^
--input D:\flex_sdk_4.6\projects\EnglishConverter\bin\js\mmt\Mediator.js ^
--input D:\flex_sdk_4.6\projects\EnglishConverter\bin\js\mmt\DomDependent.js ^
--input D:\flex_sdk_4.6\projects\EnglishConverter\bin\js\mmt\WorkFlow.js ^
--input D:\flex_sdk_4.6\projects\EnglishConverter\bin\js\mmt\Messenger.js ^
--input D:\flex_sdk_4.6\projects\EnglishConverter\bin\js\mmt\data.js ^
--compiler_jar "D:\software\closure compiler\compiler.jar" ^
--output_mode compiled ^
--compiler_flags="--compilation_level=ADVANCED_OPTIMIZATIONS" ^
--compiler_flags="--formatting=PRETTY_PRINT" ^
--output_file D:\flex_sdk_4.6\projects\EnglishConverter\bin\js\main.js
pause
例如在 Messenger.js 中我有一个函数:
/**
* Replaces words in matches with a yes/no/all box
* @param {Array} matches contains the items of myApp.data that matched words in text
* @param {string} text contains the cleaned up user input (no html)
*/
myApp.Messenger.builtReplacewithOptions=function(matches,text){
变量 matches 必须是数组,所有调用此函数的代码都使用数组调用它。为了测试类型检查,我将数组更改为字符串,如下所示:
* @param {string} matches contains the items of myApp.data that matched words in text
再次编译但没有给出警告或错误。试图在批处理文件中向编译器添加一个参数:
--compiler_flags="--jscomp_warning=checkTypes" ^
现在我收到警告。我的问题是:我必须打开各种检查吗?有没有一种方法可以打开所有检查而我只明确关闭一些检查?
最佳答案
可以设置标志--warning_level=VERBOSE
,相当于
--jscomp_warning=checkTypes --jscomp_error=checkVars \
--jscomp_warning=deprecated --jscomp_error=duplicate \
--jscomp_warning=globalThis --jscomp_warning=missingProperties \
--jscomp_warning=undefinedNames --jscomp_error=undefinedVars
仍然有一些检查将被关闭,如果需要,您必须明确启用它们。默认情况下,afaik 无法启用所有。
有关警告/错误类型的完整列表,请参阅 https://code.google.com/p/closure-compiler/wiki/Warnings .
关于javascript - 使用闭包编译器进行类型检查不是隐式的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16184322/