Chapter 16. Debugging Compiled JavaScript

Despite all of the static checks that the Closure Compiler can perform, it is still possible for your code to contain bugs. If you have leveraged the Compiler to minify your JavaScript, then it will be hard to step through your code with a debugger, as most debuggers let you step through your code only one line at a time. (Note that the IE8 debugger does not have this limitation.) In hand-written code, in which one line of code generally contains at most one statement, this works fine, but because minified code has many statements per line, using a traditional debugger will not provide the granularity that you need.

Compiling code in Advanced mode compounds this problem because renaming and inlining optimizations obfuscate and reorder code in such a way that even if you identify the line of code at which the error occurs in the compiled code, it may be extremely difficult to map back to the line in the original source code. To that end, this chapter discusses several techniques that can be used to help in debugging compiled JavaScript, many of which are specifically tailored for debugging code that was compiled using Advanced mode.

Verify That the Error Occurs in Uncompiled Mode

As explained in Chapter 1, one of the design principles of Closure Library code is that it should work in both compiled and uncompiled modes. This means that if you encounter a bug in your compiled code, your first step should be to test whether you can reproduce the ...

Get Closure: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.