AngelDoReMi / closure-templates

Automatically exported from code.google.com/p/closure-templates
Apache License 2.0
0 stars 0 forks source link

optional arguments should be tested with goog.isDef #17

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The current version of the template compiler (20100426) generates code of the 
following form:

"""
/**
 * @param {Object.<string, *>=} opt_data
 * @param {soy.StringBuilder=} opt_sb
 * @return {string|undefined}
 * @notypecheck
 */
sg.ss.intl.widgets.common.templates.all_docs_content.allDocsContent = 
function(opt_data, opt_sb) {
  var output = opt_sb || new soy.StringBuilder();
  // builds output as necessary
  if (!opt_sb) return output.toString();
};
"""

However, I believe that it would be cleaner (and more closurey) to use 
goog.isDef as follows:

"""
/**
 * @param {Object.<string, *>=} opt_data
 * @param {soy.StringBuilder=} opt_sb
 * @return {string|undefined}
 * @notypecheck
 */
sg.ss.intl.widgets.common.templates.all_docs_content.allDocsContent = 
function(opt_data, opt_sb) {
  var output = goog.isDef(opt_sb) ? opt_sb : new soy.StringBuilder();
  // builds output as necessary
  if (!goog.isDef(opt_sb)) return output.toString();
};
"""

Original issue reported on code.google.com by ahochh...@samegoal.com on 10 Jun 2010 at 8:25

GoogleCodeExporter commented 8 years ago
Closure Templates is not always used with Closure Library, so using goog.isDef 
is not correct in all cases.  We could do it only when Closure Library is used, 
but it's really not a substantial difference.

Original comment by kai.hu...@gmail.com on 11 Jun 2010 at 11:23