diff options
Diffstat (limited to 'lib/handlebars/compiler')
-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); |