3
votes

According to documentation (https://developers.google.com/closure/compiler/docs/api-tutorial3#externs), it seems the closure compiler should rename variables when no external declaration exists, including when using functions/variables from an external bit of code. The example they give is

function makeNoteDom(noteTitle, noteContent, noteContainer) {
  // Create DOM structure to represent the note.
  var headerElement = textDiv(noteTitle);
  var contentElement = textDiv(noteContent);
...
}

where the textDiv function is declared in the global scope by a third-party lib of some sort. It says textDiv should be declared external to prevent renaming.

My question is - when I put this code or similar into the Closure Compiler without any extern declarations why is textDiv not renamed (which would break the code), as the documentation indicates?

1

1 Answers

2
votes

The compiler assumes that calls to an undefined function are in fact calls to an external functions. Using the command line compiler, you can use --warning_level VERBOSE to have the compiler treat this condition as an error.

The Web Application is primarily built for demos and assumes this by default. While you can set a VERBOSE warning level, it will not change this functionality. See the Additional Web Service Options page for information on options. I've filed a bug report about this.

Due to the renaming algorithm for properties, undeclared properties will be renamed in a breaking way if that same property name isn't declared on an object in externs.