Search code examples
javascriptgoogle-closure-compiler

How to prevent Closure Compiler from renaming "true", "false" and "null"


Google Closure Compiler renames all "true", "false" and "null" occurences in code like;

var s = true, x = null, V = false;

and uses these shorthands instead; in conditions such as;

if (someVariable == s)

now; Google Analytics code defines it's own "s" variable; overriding the value "true"; and as you can see this causes a lot of problems.

I don't want to change GA code; I just want Closure Compiler to quit renaming true etc. Externs do not work.

Do you know any way to accomplish this?


Solution

  • It turns out that one can prevent Google Closure Compiler from printing out global definitions (function and/or variable) by a parameter called "output_wrapper" to the command line code such as;

    java -jar compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --output_wrapper "(function(){%output%})();" --js input.js --js_output_file output.js
    

    This way, it doesn't collide with global variables and prints all your code in an anonymous function wrapper.