diff options
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 6 | ||||
-rw-r--r-- | spec/partials.js | 15 |
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 64af5da..987d0d4 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -177,7 +177,11 @@ Compiler.prototype = { if (params.length > 1) { throw new Exception('Unsupported number of partial arguments: ' + params.length, partial); } else if (!params.length) { - params.push({type: 'PathExpression', parts: [], depth: 0}); + if (this.options.explicitPartialContext) { + this.opcode('pushLiteral', 'undefined'); + } else { + params.push({type: 'PathExpression', parts: [], depth: 0}); + } } let partialName = partial.name.original, diff --git a/spec/partials.js b/spec/partials.js index f3283ba..cc2c266 100644 --- a/spec/partials.js +++ b/spec/partials.js @@ -41,6 +41,21 @@ describe('partials', function() { 'Partials can be passed a context'); }); + it('partials with no context', function() { + var partial = '{{name}} ({{url}}) '; + var hash = {dudes: [{name: 'Yehuda', url: 'http://yehuda'}, {name: 'Alan', url: 'http://alan'}]}; + shouldCompileToWithPartials( + 'Dudes: {{#dudes}}{{>dude}}{{/dudes}}', + [hash, {}, {dude: partial}, {explicitPartialContext: true}], + true, + 'Dudes: () () '); + shouldCompileToWithPartials( + 'Dudes: {{#dudes}}{{>dude name="foo"}}{{/dudes}}', + [hash, {}, {dude: partial}, {explicitPartialContext: true}], + true, + 'Dudes: foo () foo () '); + }); + it('partials with string context', function() { var string = 'Dudes: {{>dude "dudes"}}'; var partial = '{{.}}'; |