diff --git a/mustache.js b/mustache.js index d830e55..2188673 100644 --- a/mustache.js +++ b/mustache.js @@ -773,11 +773,18 @@ var Mustache = function() { } }, compile: function(template, partials) { + var p = {}; + for (var key in partials) { + if (partials.hasOwnProperty(key)) { + p[key] = partials[key]; + } + } + var commands = []; var s = function(command) { commands.push(command); }; var renderer = new Renderer(s, 'compiler'); - renderer.render(template, {}, partials); + renderer.render(template, {}, p); return function(view, send_func) { var o = send_func ? undefined : []; diff --git a/test/unit.compiler.js b/test/unit.compiler.js index c88e2f4..b098074 100644 --- a/test/unit.compiler.js +++ b/test/unit.compiler.js @@ -15,7 +15,7 @@ module('Compiler', { }); test("Parser", function() { - expect(3); + expect(4); // matches whitespace_partial.html equals( @@ -67,6 +67,10 @@ test("Parser", function() { equals(e.message, 'Unexpected end of document.'); } + var partials = { 'partial' : '{{key}}' }; + Mustache.compile('{{>partial}}', partials ); + + equals(partials['partial'], '{{key}}', 'Partials compiler must be non-destructive'); }); test("Basic Variables", function() {