diff --git a/lib/template.js b/lib/template.js index 14f396d..65b6303 100644 --- a/lib/template.js +++ b/lib/template.js @@ -278,6 +278,11 @@ var Hogan = {}; return val; } + function objectAssign(to, source) { + for (var key in source) to[key] = source[key]; + return to; + } + function createSpecializedPartial(instance, subs, partials, stackSubs, stackPartials, stackText) { function PartialTemplate() {}; PartialTemplate.prototype = instance; @@ -290,22 +295,22 @@ var Hogan = {}; partial.buf = ''; stackSubs = stackSubs || {}; - partial.stackSubs = stackSubs; + partial.stackSubs = objectAssign({}, stackSubs); partial.subsText = stackText; for (key in subs) { - if (!stackSubs[key]) stackSubs[key] = subs[key]; + if (!partial.stackSubs[key]) partial.stackSubs[key] = subs[key]; } - for (key in stackSubs) { - partial.subs[key] = stackSubs[key]; + for (key in partial.stackSubs) { + partial.subs[key] = partial.stackSubs[key]; } stackPartials = stackPartials || {}; - partial.stackPartials = stackPartials; + partial.stackPartials = objectAssign({}, stackPartials); for (key in partials) { - if (!stackPartials[key]) stackPartials[key] = partials[key]; + if (!partial.stackPartials[key]) partial.stackPartials[key] = partials[key]; } - for (key in stackPartials) { - partial.partials[key] = stackPartials[key]; + for (key in partial.stackPartials) { + partial.partials[key] = partial.stackPartials[key]; } return partial; diff --git a/test/index.js b/test/index.js index ec0777e..7787487 100644 --- a/test/index.js +++ b/test/index.js @@ -927,6 +927,40 @@ test("Recursion in inherited templates", function() { is(s, "override override override don't recurse", "matches expected recursive output"); }); +test('Using a inherited partials twice with different sub values should have a different output', function() { + is( + Hogan + .compile('{{