ignore extra block helper args as intended

This commit is contained in:
David Greenspan
2012-07-11 20:48:47 -07:00
parent 20af33e4ea
commit cd3ca61ec3
3 changed files with 12 additions and 3 deletions

View File

@@ -224,10 +224,12 @@ Handlebars.evaluate = function (ast, data, options) {
if (isNested && values.length > 1) {
// at least one positional argument; not no args
// or only hash args.
if (typeof values[1] === "function")
var oneArg = values[1];
if (typeof oneArg === "function")
// invoke the positional arguments
// (and hash arguments) as a nested helper invocation.
values = [values[0], apply(values.slice(1), {hash:hash})];
oneArg = apply(values.slice(1), {hash:hash});
values = [values[0], oneArg];
// keyword args don't go to the block helper, then.
extra.hash = {};
} else {

View File

@@ -181,4 +181,5 @@
(nokeys={{#arg_and_dict "foo" x="foo"}}{{/arg_and_dict}})
(nokeys={{#arg_and_dict tree x="foo"}}{{/arg_and_dict}})
(biggie={{#get_arg helperListFour platypus thisTest fancyhelper.currentFruit fancyhelper.currentCountry.unicorns a=platypus b=thisTest c=fancyhelper.currentFruit d=fancyhelper.currentCountry.unicorns}}{{/get_arg}})
(twoArgBlock={{#two_args "foo" "foo"}}{{/two_args}})
</template>

View File

@@ -292,6 +292,10 @@ Tinytest.add("templating - helpers and dots", function(test) {
Template.test_helpers_i.get_arg = function(arg) {
return arg;
};
Template.test_helpers_i.two_args = function(arg1, arg2) {
return [typeof arg1 === "string",
typeof arg2 === "string"].join();
};
Template.test_helpers_i.helperListFour = listFour;
trials =
@@ -305,5 +309,7 @@ Tinytest.add("templating - helpers and dots", function(test) {
test.equal(trials[3], "(nokeys=0)");
test.equal(trials[4],
'(biggie=eggs leaf guava 0 a:eggs b:leaf c:guava d:0)');
test.equal(trials.length, 5);
// can't pass > 1 positional arg to block helper
test.equal(trials[5], "(twoArgBlock=true,false)");
test.equal(trials.length, 6);
});