Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/handlebars/compiler/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ export function prepareMustache(path, params, hash, open, strip, locInfo) {
return new this.MustacheStatement(path, params, hash, escaped, strip, this.locInfo(locInfo));
}

export function prepareRawBlock(openRawBlock, content, close, 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);
}

locInfo = this.locInfo(locInfo);
let program = new this.Program([content], null, {}, locInfo);
let program = new this.Program(contents, null, {}, locInfo);

return new this.BlockStatement(
openRawBlock.path, openRawBlock.params, openRawBlock.hash,
Expand Down
10 changes: 10 additions & 0 deletions spec/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ describe('helpers', function() {
'raw block helper gets raw content');
});

it('helper for nested raw block gets raw content', function() {
var string = '{{{{a}}}} {{{{b}}}} {{{{/b}}}} {{{{/a}}}}';
var helpers = {
a: function(options) {
return options.fn();
}
};
shouldCompileTo(string, [{}, helpers], ' {{{{b}}}} {{{{/b}}}} ', 'raw block helper should get nested raw block as raw content');
});

it('helper block with complex lookup expression', function() {
var string = '{{#goodbyes}}{{../name}}{{/goodbyes}}';
var hash = {name: 'Alan'};
Expand Down
15 changes: 12 additions & 3 deletions src/handlebars.l
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,21 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/{LOOKAHEAD}
return 'CONTENT';
}

// nested raw block will create stacked 'raw' condition
<raw>"{{{{"/[^/] this.begin('raw'); return 'CONTENT';
<raw>"{{{{/"[^\s!"#%-,\.\/;->@\[-\^`\{-~]+/[=}\s\/.]"}}}}" {
yytext = yytext.substr(5, yyleng-9);
this.popState();
return 'END_RAW_BLOCK';
// Should be using `this.topState()` below, but it currently
// returns the second top instead of the first top. Opened an
// issue about it at https://github.com/zaach/jison/issues/291
if (this.conditionStack[this.conditionStack.length-1] === 'raw') {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be using this.topState() here, but it currently returns the second top instead of the first top. Opened an issue about it at zaach/jison#291

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should be a comment in the source.

return 'CONTENT';
} else {
yytext = yytext.substr(5, yyleng-9);
return 'END_RAW_BLOCK';
}
}
<raw>[^\x00]*?/("{{{{/") { return 'CONTENT'; }
<raw>[^\x00]*?/("{{{{") { return 'CONTENT'; }

<com>[\s\S]*?"--"{RIGHT_STRIP}?"}}" {
this.popState();
Expand Down
2 changes: 1 addition & 1 deletion src/handlebars.yy
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ content
;

rawBlock
: openRawBlock content END_RAW_BLOCK -> yy.prepareRawBlock($1, $2, $3, @$)
: openRawBlock content+ END_RAW_BLOCK -> yy.prepareRawBlock($1, $2, $3, @$)
;

openRawBlock
Expand Down