diff options
Diffstat (limited to 'lib/handlebars/compiler/javascript-compiler.js')
-rw-r--r-- | lib/handlebars/compiler/javascript-compiler.js | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js index d90f0b1..f0bd58b 100644 --- a/lib/handlebars/compiler/javascript-compiler.js +++ b/lib/handlebars/compiler/javascript-compiler.js @@ -77,6 +77,9 @@ JavaScriptCompiler.prototype = { } } + // Flush any trailing content that might be pending. + this.pushSource(''); + return this.createFunctionContext(asObject); }, @@ -233,7 +236,14 @@ JavaScriptCompiler.prototype = { // // Appends the string value of `content` to the current buffer appendContent: function(content) { - this.pushSource(this.appendToBuffer(this.quotedString(content))); + if (this.pendingContent) { + content = this.pendingContent + content; + } + if (this.stripNext) { + content = content.replace(/^\s+/, ''); + } + + this.pendingContent = content; }, // [append] @@ -612,7 +622,14 @@ JavaScriptCompiler.prototype = { }, pushSource: function(source) { - this.source.push(source); + if (this.pendingContent) { + this.source.push(this.appendToBuffer(this.quotedString(this.pendingContent))); + this.pendingContent = undefined; + } + + if (source) { + this.source.push(source); + } }, pushStack: function(item) { |