Why is the Google Closure compiler NOT renaming these external variables?

According to the documentation ( https://developers.google.com/closure/compiler/docs/api-tutorial3#externs ), it seems that the closure compiler should rename the variables if no external declaration exists, including when using functions / variables from external code bit. 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 the third party lib. It says that textDiv must be declared external to prevent renaming.

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

+3


source to share


1 answer


The compiler assumes that calls to undefined function are actually calls to external functions. Using a command line compiler, you can use --warning_level VERBOSE

to make the compiler treat this condition as an error.

The web application is mainly built for demos and assumes this by default. Although you can set the warning level VERBOSE

, this will not change this functionality. For more information on parameters, see the Advanced Web Service Parameters page . I have filed a bug report on this.



Thanks to the property renaming algorithm, undeclared properties will be renamed intermittently unless this same property name is declared on the object in externs.

+2


source







All Articles