diff options
author | kpdecker <kpdecker@gmail.com> | 2015-08-13 01:50:51 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2015-08-13 01:51:17 -0500 |
commit | ea3a5a1eb6e488f8dc0189c68a6019c76ffad740 (patch) | |
tree | f86322b074f3145f40ab79d19936d7708b18b1b2 /lib | |
parent | 269dd492bb3ccb54516a3f7f6caba80dbaaad862 (diff) | |
download | handlebars.js-ea3a5a1eb6e488f8dc0189c68a6019c76ffad740.zip handlebars.js-ea3a5a1eb6e488f8dc0189c68a6019c76ffad740.tar.gz handlebars.js-ea3a5a1eb6e488f8dc0189c68a6019c76ffad740.tar.bz2 |
Add ignoreStandalone compiler option
Fixes #1072
Diffstat (limited to 'lib')
-rw-r--r-- | lib/handlebars/compiler/base.js | 2 | ||||
-rw-r--r-- | lib/handlebars/compiler/whitespace-control.js | 14 |
2 files changed, 10 insertions, 6 deletions
diff --git a/lib/handlebars/compiler/base.js b/lib/handlebars/compiler/base.js index 7075d9b..85c2997 100644 --- a/lib/handlebars/compiler/base.js +++ b/lib/handlebars/compiler/base.js @@ -20,6 +20,6 @@ export function parse(input, options) { return new yy.SourceLocation(options && options.srcName, locInfo); }; - let strip = new WhitespaceControl(); + let strip = new WhitespaceControl(options); return strip.accept(parser.parse(input)); } diff --git a/lib/handlebars/compiler/whitespace-control.js b/lib/handlebars/compiler/whitespace-control.js index 5b76944..d1b743d 100644 --- a/lib/handlebars/compiler/whitespace-control.js +++ b/lib/handlebars/compiler/whitespace-control.js @@ -1,10 +1,13 @@ import Visitor from './visitor'; -function WhitespaceControl() { +function WhitespaceControl(options = {}) { + this.options = options; } WhitespaceControl.prototype = new Visitor(); WhitespaceControl.prototype.Program = function(program) { + const doStandalone = !this.options.ignoreStandalone; + let isRoot = !this.isRootSeen; this.isRootSeen = true; @@ -31,7 +34,7 @@ WhitespaceControl.prototype.Program = function(program) { omitLeft(body, i, true); } - if (inlineStandalone) { + if (doStandalone && inlineStandalone) { omitRight(body, i); if (omitLeft(body, i)) { @@ -42,13 +45,13 @@ WhitespaceControl.prototype.Program = function(program) { } } } - if (openStandalone) { + if (doStandalone && openStandalone) { omitRight((current.program || current.inverse).body); // Strip out the previous content node if it's whitespace only omitLeft(body, i); } - if (closeStandalone) { + if (doStandalone && closeStandalone) { // Always strip the next node omitRight(body, i); @@ -106,7 +109,8 @@ WhitespaceControl.prototype.BlockStatement = function(block) { } // Find standalone else statments - if (isPrevWhitespace(program.body) + if (!this.options.ignoreStandalone + && isPrevWhitespace(program.body) && isNextWhitespace(firstInverse.body)) { omitLeft(program.body); omitRight(firstInverse.body); |