Can you provide a stack trace?
I don't really understand why you're calling optimize() separately?
The compile() method already calls optimize() directly, but it does
all the messy work of checking if there are any errors.
>
> could you still give me some hints on how to get the closure compiler
> to report all the warnings and errors it should be able to detect?
It sounds like you already figured that part out though? You basically
just want to look at CompilerOptions and turn on everything you want.
Nick
> hi,
>
> from looking at the compiler sources i got the idea that some errors
> are only detected when the closure compiler tries to optimize the js
> code.
That's correct; some of the warnings are only produced because the compiler noticed something fishy while trying to optimize.
If the optimizations are off, or if the compiler couldn't optimize a particular piece of code to the point where it would notice the problem, then it won't produce a warning.
> on a different note, i'm not able to get the closure compiler to
> generate the following warnings
>
> // Produces JSC_INDEX_OUT_OF_BOUNDS_ERROR error:
> var x = [0, 1, 2];
> alert(x[3]);
In this case, you'll need --compilation_level ADVANCED_OPTIMIZATIONS for this error to be reported.
The compiler only reports this error when attempting folding, but won't t even detect this as a folding opportunity unless inlining of global variables is turned on, which requires ADVANCED_OPTIMIZATIONS.
The compiler will detect this error in non-global scope (i.e. inside a function) with only SIMPLE_OPTIMIZATIONS.
There are several other optimizations that the compiler applies inside functions, but not in global scope -- this can be confusing because short little programs for testing/exploration are often only in the global scope.
> // Produces JSC_INVALID_GETELEM_INDEX_ERROR:
> var x = [1,2,3];
> alert(x['a']);
I believe this is a mistake in the documentation. With ADVANCED_OPTIMIZATIONS, the compiler reports this error for:
var x = [1,2,3];
alert(x[2.3])
but does not do so for string indices (because, for example, x['length'] would be fine).
If distinguishing between x['a'] and x['length'] is important t to you, please file an issue:
http://code.google.com/p/closure-compiler/issues/list
Devin