summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/javascript-compiler.js
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2013-07-30 11:07:09 -0500
committerkpdecker <kpdecker@gmail.com>2013-10-14 22:50:50 -0500
commitc776f171aba41dc8cc620b26372f8f1eda9525e1 (patch)
tree1af4e5dae1d3515056d640c33e33e4de715d4932 /lib/handlebars/compiler/javascript-compiler.js
parent6b0b3fa2ca4e8d274a71f8b8337e628e3466a7c5 (diff)
downloadhandlebars.js-c776f171aba41dc8cc620b26372f8f1eda9525e1.zip
handlebars.js-c776f171aba41dc8cc620b26372f8f1eda9525e1.tar.gz
handlebars.js-c776f171aba41dc8cc620b26372f8f1eda9525e1.tar.bz2
Implement strip opcode
Diffstat (limited to 'lib/handlebars/compiler/javascript-compiler.js')
-rw-r--r--lib/handlebars/compiler/javascript-compiler.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js
index f0bd58b..b04ef1a 100644
--- a/lib/handlebars/compiler/javascript-compiler.js
+++ b/lib/handlebars/compiler/javascript-compiler.js
@@ -75,6 +75,11 @@ JavaScriptCompiler.prototype = {
} else {
this[opcode.opcode].apply(this, opcode.args);
}
+
+ // Reset the stripNext flag if it was not set by this operation.
+ if (opcode.opcode !== this.stripNext) {
+ this.stripNext = false;
+ }
}
// Flush any trailing content that might be pending.
@@ -246,6 +251,20 @@ JavaScriptCompiler.prototype = {
this.pendingContent = content;
},
+ // [strip]
+ //
+ // On stack, before: ...
+ // On stack, after: ...
+ //
+ // Removes any trailing whitespace from the prior content node and flags
+ // the next operation for stripping if it is a content node.
+ strip: function() {
+ if (this.pendingContent) {
+ this.pendingContent = this.pendingContent.replace(/\s+$/, '');
+ }
+ this.stripNext = 'strip';
+ },
+
// [append]
//
// On stack, before: value, ...