Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CallExtensionAsync parse #1357

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion nunjucks/src/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function _liftFilters(node, asyncFilters, prop) {
return descNode;
} else if ((descNode instanceof nodes.Filter &&
lib.indexOf(asyncFilters, descNode.name.value) !== -1) ||
descNode instanceof nodes.CallExtensionAsync) {
descNode instanceof nodes.FilterAsync) {
symbol = new nodes.Symbol(descNode.lineno,
descNode.colno,
gensym());
Expand Down
44 changes: 44 additions & 0 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,5 +256,49 @@
expect(render('{{ "FOOBAR" is upper }}')).to.be('true');
expect(render('{{ "Foobar" is upper }}')).to.be('false');
});

it('should render async extensions inside macro', function(done) {
function AsyncExtension() {
this.tags = ['asyncextension'];

this.parse = function(parser, nodes, lexer) {
var tok, args, body, errorBody;
tok = parser.nextToken();
args = parser.parseSignature(null, true);
parser.advanceAfterBlockEnd(tok.value);
body = parser.parseUntilBlocks('error', 'endasyncextension');
errorBody = null;

if (parser.skipSymbol('error')) {
parser.skip(lexer.TOKEN_BLOCK_END);
errorBody = parser.parseUntilBlocks('endasyncextension');
}

parser.advanceAfterBlockEnd();

return new nodes.CallExtensionAsync(this, 'run', args, [body, errorBody]);
};

this.run = function(context, url, body, errorBody, callback) {
callback(null, 'Foo async extension content');
};
}

render(
'{% macro wrap() %}{{ caller() }}{% endmacro %}' +
'{% call wrap() %}{% asyncextension "foobar" %}1{% error %}2{% endasyncextension %}{% endcall %}',
{},
{
extensions: {
AsyncExtension: new AsyncExtension()
}
},
function(err, str) {
expect(str).to.be('Foo async extension content');

done();
}
);
});
});
}());