Domanda

java -jar SoyToJsSrcCompiler.jar --shouldGenerateJsdoc --outputPathFormat 
           simple.js --srcs simple.soy

SoyToJsSrcCompiler generates a js file which looks like this:

if (typeof templates == 'undefined') { var templates = {}; }
if (typeof templates.simple == 'undefined') { templates.simple = {}; }

/**
 * @param {Object.<string, *>=} opt_data
 * @param {(null|undefined)=} opt_ignored
 * @return {string}
 * @notypecheck
 */

 templates.simple.tinyButton = function(opt_data, opt_ignored) {
     .....
 };

I am using Closure Compiler with --warning_level=VERBOSE and --compilation_level ADVANCED_OPTIMIZATIONS

and I am getting this warning:

simple.js:1: WARNING - Variable referenced before declaration: templates
if (typeof templates == 'undefined') { var templates = {}; }

How can I clear this warning?

È stato utile?

Soluzione

One workaround is to declare the variables in an externs file with:

/** @suppress {duplicate} */
var template;

But the Soy compiler should be fixed. I expect people don't see this because you typically use it with Closure Library and in that mode the Soy compiler should be generating:

goog.provide('template.simple')

Altri suggerimenti

If you are using the Closure compiler with Soy, you should pass either --shouldProvideRequireJsFunctions or --shouldProvideRequireJsFunctions. Otherwise it assumes you are not going to use a compiler and generates code that browsers understand but is otherwise kind of iffy.

(Source: I help maintain the Soy compiler. We generally never test them compiler without either of those flags passed. It might make sense to make at least one of those flags mandatory because it really doesn't work well without them.)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top