Skip to content

Commit 7172d16

Browse files
committed
Provide clear throw on {{#each}}
Fixes #773
1 parent 3cdf14d commit 7172d16

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

lib/handlebars/base.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,8 @@ function registerDefaultHelpers(instance) {
9797
});
9898

9999
instance.registerHelper('each', function(context, options) {
100-
// Allow for {{#each}}
101100
if (!options) {
102-
options = context;
103-
context = this;
101+
throw new Exception('Must pass iterator to #each');
104102
}
105103

106104
var fn = options.fn, inverse = options.inverse;

spec/builtins.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*global CompilerContext, shouldCompileTo, compileWithPartials, handlebarsEnv */
1+
/*global CompilerContext, shouldCompileTo, shouldThrow, compileWithPartials, handlebarsEnv */
22
describe('builtin helpers', function() {
33
describe('#if', function() {
44
it("if", function() {
@@ -182,9 +182,10 @@ describe('builtin helpers', function() {
182182
});
183183

184184
it("each on implicit context", function() {
185-
var string = "{{#each}}{{text}}! {{/each}}cruel world!";
186-
var hash = [{text: "goodbye"}, {text: "Goodbye"}, {text: "GOODBYE"}];
187-
shouldCompileTo(string, [hash], "goodbye! Goodbye! GOODBYE! cruel world!");
185+
shouldThrow(function() {
186+
var template = CompilerContext.compile("{{#each}}{{text}}! {{/each}}cruel world!");
187+
template({});
188+
}, handlebarsEnv.Exception, 'Must pass iterator to #each');
188189
});
189190
});
190191

0 commit comments

Comments
 (0)