diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/handlebars/compiler/helpers.js | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/lib/handlebars/compiler/helpers.js b/lib/handlebars/compiler/helpers.js index e04f4dd..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,20 +188,16 @@ export function prepareProgram(statements, loc) { } -export function preparePartialBlock(openPartialBlock, program, close, locInfo) { - if (openPartialBlock.name.original !== close.path.original) { - let errorNode = {loc: openPartialBlock.name.loc}; - - throw new Exception(openPartialBlock.name.original + " doesn't match " + close.path.original, errorNode); - } +export function preparePartialBlock(open, program, close, locInfo) { + validateClose(open, close); return { type: 'PartialBlockStatement', - path: openPartialBlock.name, - params: openPartialBlock.params, - hash: openPartialBlock.hash, + name: open.path, + params: open.params, + hash: open.hash, program, - openStrip: openPartialBlock.strip, + openStrip: open.strip, closeStrip: close && close.strip, loc: this.locInfo(locInfo) }; |