diff --git a/lib/handlebars/compiler/helpers.js b/lib/handlebars/compiler/helpers.js index c093d65ad..1f71bd79e 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 = { @@ -71,11 +81,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 = new this.Program(contents, null, {}, locInfo); @@ -88,11 +94,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; @@ -147,17 +150,13 @@ 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 new this.PartialBlockStatement( - openPartialBlock.name, openPartialBlock.params, openPartialBlock.hash, + open.path, open.params, open.hash, program, - openPartialBlock.strip, close && close.strip, + open.strip, close && close.strip, this.locInfo(locInfo)); } diff --git a/src/handlebars.yy b/src/handlebars.yy index bc2fd2791..7dff97d74 100644 --- a/src/handlebars.yy +++ b/src/handlebars.yy @@ -84,7 +84,7 @@ partialBlock : openPartialBlock program closeBlock -> yy.preparePartialBlock($1, $2, $3, @$) ; openPartialBlock - : OPEN_PARTIAL_BLOCK partialName param* hash? CLOSE -> { name: $2, params: $3, hash: $4, strip: yy.stripFlags($1, $5) } + : OPEN_PARTIAL_BLOCK partialName param* hash? CLOSE -> { path: $2, params: $3, hash: $4, strip: yy.stripFlags($1, $5) } ; param