diff options
author | kpdecker <kpdecker@gmail.com> | 2014-11-05 22:04:37 -0600 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2014-11-05 22:28:12 -0600 |
commit | 9665379cdc20d6ef9f8e21157f623b69d6f21db0 (patch) | |
tree | 894aacfc05965b55569bdc7136ae4cbf6cb38690 /lib/handlebars/compiler/javascript-compiler.js | |
parent | a7000f81292816065b122389ea3454ad85c1798e (diff) | |
download | handlebars.js-9665379cdc20d6ef9f8e21157f623b69d6f21db0.zip handlebars.js-9665379cdc20d6ef9f8e21157f623b69d6f21db0.tar.gz handlebars.js-9665379cdc20d6ef9f8e21157f623b69d6f21db0.tar.bz2 |
Use terinary operator for inline appends
Allows for append operations to avoid breaking inline chain.
Diffstat (limited to 'lib/handlebars/compiler/javascript-compiler.js')
-rw-r--r-- | lib/handlebars/compiler/javascript-compiler.js | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js index d41cacd..61e99cb 100644 --- a/lib/handlebars/compiler/javascript-compiler.js +++ b/lib/handlebars/compiler/javascript-compiler.js @@ -289,13 +289,18 @@ JavaScriptCompiler.prototype = { // If `value` is truthy, or 0, it is coerced into a string and appended // Otherwise, the empty string is appended append: function() { - // Force anything that is inlined onto the stack so we don't have duplication - // when we examine local - this.flushInline(); - var local = this.popStack(); - this.pushSource('if (' + local + ' != null) { ' + this.appendToBuffer(local) + ' }'); - if (this.environment.isSimple) { - this.pushSource("else { " + this.appendToBuffer("''") + " }"); + if (this.isInline()) { + this.replaceStack(function(current) { + return ' != null ? ' + current + ' : ""'; + }); + + this.pushSource(this.appendToBuffer(this.popStack())); + } else { + var local = this.popStack(); + this.pushSource('if (' + local + ' != null) { ' + this.appendToBuffer(local) + ' }'); + if (this.environment.isSimple) { + this.pushSource("else { " + this.appendToBuffer("''") + " }"); + } } }, |