Search code examples
javascriptgoogle-closure-compiler

Is there a way to enable dead code elimination in Closure compiler, without renaming?


I would like to check that certain code is being dead code eliminated by Closure compiler, but this is hard to do when everything is renamed.

It looks like "advanced optimizations" enables both renaming and DCE, without any granularity.

Is there a way to achieve the question in the title?


Solution

  • The easiest thing to do is use the --debug flag as documented here:

    https://github.com/google/closure-compiler/wiki/Flags-and-Options

    This uses a alternate renaming scheme that retains the original name as part of the new name. This is also useful for trying to understand what will and won't be renamed as part of advanced optimizations.

    Otherwise, using the Java API it is possible to take full control of the optimizations that are run and disable renaming directly using the CompilerOptions#setRenamingPolicy[1]

    [1] https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/CompilerOptions.java#L1565