diff options
author | Kevin Decker <kpdecker@gmail.com> | 2015-08-23 23:45:17 -0500 |
---|---|---|
committer | Kevin Decker <kpdecker@gmail.com> | 2015-08-23 23:45:17 -0500 |
commit | c727e1f97c471ec6be26b54dcd7422fd521a2471 (patch) | |
tree | 0979b5f54c7e98b317545a573d43ec6e8566d576 /lib/handlebars/compiler/helpers.js | |
parent | 2571dd8e8e43fd320672763564b16a5b3ae33966 (diff) | |
parent | 1c274088c1ea9969f7a676fd5bebd11698f73116 (diff) | |
download | handlebars.js-c727e1f97c471ec6be26b54dcd7422fd521a2471.zip handlebars.js-c727e1f97c471ec6be26b54dcd7422fd521a2471.tar.gz handlebars.js-c727e1f97c471ec6be26b54dcd7422fd521a2471.tar.bz2 |
Merge pull request #1076 from wycats/partial-block
Implement partial blocks
Diffstat (limited to 'lib/handlebars/compiler/helpers.js')
-rw-r--r-- | lib/handlebars/compiler/helpers.js | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/lib/handlebars/compiler/helpers.js b/lib/handlebars/compiler/helpers.js index bf72034..9c40f0d 100644 --- a/lib/handlebars/compiler/helpers.js +++ b/lib/handlebars/compiler/helpers.js @@ -1,5 +1,15 @@ import Exception from '../exception'; +function validateClose(open, close) { + close = close.path ? close.path.original : close; + + if (open.path.original !== close) { + let errorNode = {loc: open.path.loc}; + + throw new Exception(open.path.original + " doesn't match " + close, errorNode); + } +} + export function SourceLocation(source, locInfo) { this.source = source; this.start = { @@ -86,11 +96,7 @@ export function prepareMustache(path, params, hash, open, strip, locInfo) { } export function prepareRawBlock(openRawBlock, contents, close, locInfo) { - if (openRawBlock.path.original !== close) { - let errorNode = {loc: openRawBlock.path.loc}; - - throw new Exception(openRawBlock.path.original + " doesn't match " + close, errorNode); - } + validateClose(openRawBlock, close); locInfo = this.locInfo(locInfo); let program = { @@ -114,11 +120,8 @@ export function prepareRawBlock(openRawBlock, contents, close, locInfo) { } export function prepareBlock(openBlock, program, inverseAndProgram, close, inverted, locInfo) { - // When we are chaining inverse calls, we will not have a close path - if (close && close.path && openBlock.path.original !== close.path.original) { - let errorNode = {loc: openBlock.path.loc}; - - throw new Exception(openBlock.path.original + ' doesn\'t match ' + close.path.original, errorNode); + if (close && close.path) { + validateClose(openBlock, close); } program.blockParams = openBlock.blockParams; @@ -185,3 +188,18 @@ export function prepareProgram(statements, loc) { } +export function preparePartialBlock(open, program, close, locInfo) { + validateClose(open, close); + + return { + type: 'PartialBlockStatement', + name: open.path, + params: open.params, + hash: open.hash, + program, + openStrip: open.strip, + closeStrip: close && close.strip, + loc: this.locInfo(locInfo) + }; +} + |