Debugging the Closure Compiled Javascript Compiler

I have a complex dojo application that works correctly uncompiled, but after compiling with the Google Closure Compiler , I get subtle differences in some types of behavior.

Be that as it may, it is very difficult to debug, and I could not find information on the possible functional differences between compiled and uncompiled Javascript with Google Closure.

Can someone point me towards the known differences or share any similar experiences and some ideas on where to start looking?

+4
source share
3 answers

General Debugging Compiler Debugging Tips

  • Use the VERBOSE warning level. This includes all checks.
  • Use the debug flag. This makes the renamed characters ridiculously long, but they are named so that you can find the original. If the code works with the debug flag, but not without it, this is almost certainly a renaming problem.
  • Definitely use formatting=PRETTY_PRINT . Debugging compressed code is painless.
  • Use source maps
  • Disable type optimization with --use_types_for_optimization false . Incorrect type annotations can cause the compiler to make invalid assumptions.

UPDATE: Starting with compiler version 20150315, type optimizations are enabled by default.

+9
source

Using Chad's answer, I found an error where my working code looks like this:

 a = [b, b = a][0]; // swap variable values 

Compiled for:

 a = b; 

It can be fixed in later versions because tests with the Closure online compiler do not show the same error. Fixed by not trying to be smart, and using a third variable to store the old value when replacing values.

+1
source

A couple of issues I saw with dojo 1.3 (pre-clos):

  • If you have a class property called class, it should be specified. So, {class: "css"} needs to be written as {"class": "css"}, this includes any widget fields.
  • Be sure to remove any debugger instructions.
0
source

All Articles