Type checking with closure compiler not implicitly on?
Asked Answered
A

1

5

I am compiling files and get working compiled code but the annotations seem to be completely ignored; no warnings no errors. Using calcdeps.py to compile my code with the following command:

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

For example in Messenger.js I have a function:

/**
 * 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){

The variable matches has to be an Array and all code calling this function call it with an Array. To test type checking I changed the Array to string like so:

 * @param {string} matches contains the items of myApp.data that matched words in text

Compiled again but no warning or error is given. tried to add a parameter to the compiler in the batch file:

--compiler_flags="--jscomp_warning=checkTypes" ^

Now I get warnings. My question is: do I have to turn on all kinds of checking? Is there a way that all checks are on and I only explicitly turn off some?

Abdulabdulla answered 24/4, 2013 at 5:51 Comment(0)
A
7

You can set the flag --warning_level=VERBOSE, which is equivalent to

--jscomp_warning=checkTypes --jscomp_error=checkVars \
--jscomp_warning=deprecated --jscomp_error=duplicate \
--jscomp_warning=globalThis --jscomp_warning=missingProperties \
--jscomp_warning=undefinedNames --jscomp_error=undefinedVars

There are still some checks which will be off and which you have to enable explicitly if you want them. There is no way afaik to enable all by default.

For a complete list of warning/error types, see https://code.google.com/p/closure-compiler/wiki/Warnings.

Anthill answered 24/4, 2013 at 5:58 Comment(4)
Thank you, it works. Got a lot of warnings about goog.events having unknown types and console.log is broken but it does what I want it to do. Fixed the console.log for now using the mediator passing console.log calls to the (mediator)event handler of log and logging from compiled code using myApp.mediator.trigger("log",someObject); The actual call to console.log is done from the html page (uncompiled code). This until I figure out how to use goog.debug but I am not sure if that is as informative as firebug's console.log.Abdulabdulla
Unknown types are due to a missing deps.js file (which provide forward type declarations). I don't know why the Closure Library folks don't do this by default. What is broken about console.log?Arielle
@Arielle console.log needs to be window.console.log. I've been meaning to submit a change to fix that, but it's been pretty far down on my list.Buchbinder
Weird, it just needs to be part of the default externs: code.google.com/p/closure-compiler/source/browse/contrib/…Arielle

© 2022 - 2024 — McMap. All rights reserved.