diff --git a/packages/spacebars/compile_tests.js b/packages/spacebars/compile_tests.js index fcaea0d7bb..ca46188015 100644 --- a/packages/spacebars/compile_tests.js +++ b/packages/spacebars/compile_tests.js @@ -113,4 +113,84 @@ Tinytest.add("spacebars - compiler output", function (test) { }; }); + run("{{> foo bar}}", + function() { + var self = this; + return function() { + return Spacebars.include(Template["foo"] || self.lookup("foo"), { + data: self.lookup("bar") + }); + }; + }); + + run("{{> foo x=bar}}", + function() { + var self = this; + return function() { + return Spacebars.include(Template["foo"] || self.lookup("foo"), { + x: self.lookup("bar") + }); + }; + }); + + run("{{> foo bar.baz}}", + function() { + var self = this; + return function() { + return Spacebars.include(Template["foo"] || self.lookup("foo"), { + data: function() { + return Spacebars.dot(self.lookup("bar"), "baz"); + } + }); + }; + }); + + run("{{> foo x=bar.baz}}", + function() { + var self = this; + return function() { + return Spacebars.include(Template["foo"] || self.lookup("foo"), { + x: function() { + return Spacebars.dot(self.lookup("bar"), "baz"); + } + }); + }; + }); + + run("{{> foo bar baz}}", + {fail: 'Only one positional argument'}); + + run("{{#foo bar baz}}aaa{{/foo}}", + function() { + var self = this; + return function() { + return Spacebars.include(Template["foo"] || self.lookup("foo"), { + __content: UI.block(function() { + var self = this; + return "aaa"; + }), + data: function() { + return Spacebars.call2(self.lookup("bar"), self.lookup("baz")); + } + }); + }; + }); + + run("{{#foo p.q r.s}}aaa{{/foo}}", + function() { + var self = this; + return function() { + return Spacebars.include(Template["foo"] || self.lookup("foo"), { + __content: UI.block(function() { + var self = this; + return "aaa"; + }), + data: function() { + return Spacebars.call2( + Spacebars.dot(self.lookup("p"), "q"), + Spacebars.dot(self.lookup("r"), "s")); + } + }); + }; + }); }); diff --git a/packages/spacebars/spacebars.js b/packages/spacebars/spacebars.js index 77301761be..7a1a6c54f8 100644 --- a/packages/spacebars/spacebars.js +++ b/packages/spacebars/spacebars.js @@ -1465,6 +1465,13 @@ var codeGenInclusionArgs = function (tag) { 'UI.block(' + Spacebars.compile2(tag.elseContent) + ')'); } + // precalculate the number of positional args + var numPosArgs = 0; + _.each(tag.args, function (arg) { + if (arg.length === 2) + numPosArgs++; + }); + _.each(tag.args, function (arg) { var argType = arg[0]; var argValue = arg[1]; @@ -1487,11 +1494,8 @@ var codeGenInclusionArgs = function (tag) { // while `Spacebars.dot(self.lookup("foo"), "bar")` may establish // dependencies. // - // In the multi-positional-arg construct, no point wrapping - // pos args after the first in a closure, as we have to - // rerun the whole thing anyway if one changes. - if (! ((path.length === 1) || - ((! isKeyword) && posArgs.length))) + // In the multi-positional-arg construct, don't wrap pos args. + if (! ((path.length === 1) || (numPosArgs > 1))) argCode = 'function () { return ' + argCode + '; }'; break; default: