Start to fix dots in block helper args

This commit is contained in:
David Greenspan
2013-12-05 14:51:57 -08:00
parent 197a812a47
commit 54ead3fca2
2 changed files with 89 additions and 5 deletions

View File

@@ -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"));
}
});
};
});
});

View File

@@ -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: