summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2015-09-01 01:05:00 -0500
committerkpdecker <kpdecker@gmail.com>2015-09-01 01:05:00 -0500
commitb63d74a7b3be48e388d47752676e26136ad7ff10 (patch)
treed80caf75816c9b6fb024bfd3ba550b2dfc4b13b8
parente7a64f018ca541a7e0ac8ab2108ed86820bb47b1 (diff)
downloadhandlebars.js-b63d74a7b3be48e388d47752676e26136ad7ff10.zip
handlebars.js-b63d74a7b3be48e388d47752676e26136ad7ff10.tar.gz
handlebars.js-b63d74a7b3be48e388d47752676e26136ad7ff10.tar.bz2
Add explicitPartialContext compiler flag
Fixes #1032
-rw-r--r--lib/handlebars/compiler/compiler.js6
-rw-r--r--spec/partials.js15
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 = '{{.}}';