diff --git a/src/compiler.js b/src/compiler.js index e0a05266..646a93fa 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -581,7 +581,7 @@ var Compiler = Object.extend({ compileIfAsync: function(node, frame) { this.emit('(function(cb) {'); this.compileIf(node, frame, true); - this.emit('})(function() {'); + this.emit('})(' + this.makeCallback()); this.addScopeLevel(); }, diff --git a/tests/compiler.js b/tests/compiler.js index 5f6b3d21..85d5d398 100644 --- a/tests/compiler.js +++ b/tests/compiler.js @@ -1209,6 +1209,20 @@ finish(done); }); + it('should throw an error when including a file that calls an undefined macro even inside {% if %} tag', function(done) { + render( + '{% if true %}{% include "undefined-macro.html" %}{% endif %}', + {}, + { noThrow: true }, + function(err, res) { + expect(res).to.be(undefined); + expect(err).to.match(/Unable to call `\w+`, which is undefined or falsey/); + } + ); + + finish(done); + }); + it('should throw an error when including a file that imports macro that calls an undefined macro', function(done) { render( '{% include "import-macro-call-undefined-macro.html" %}',