Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion mustache.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
// This anonymous function wraps the generated function so we can do
// argument coercion, setup some variables, and handle any errors
// encountered while executing it.
return function (view, partials) {
var template = function (view, partials) {
partials = partials || {};

var stack = [view]; // context stack
Expand All @@ -487,6 +487,8 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
throw debug(e.error, template, e.line, options.file);
}
};
template.compiled = true;
return template;
}

// Cache of pre-compiled templates.
Expand All @@ -511,6 +513,10 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
function compile(template, options) {
options = options || {};

if (typeof template === "function" && template.compiled) {
return template;
}

// Use a pre-compiled version from the cache if we have one.
if (options.cache !== false) {
if (!_cache[template]) {
Expand Down