diff options
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index d4ee32c..7b759c1 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -753,16 +753,21 @@ Handlebars.precompile = function(string, options) { return new Handlebars.JavaScriptCompiler().compile(environment, options); }; -Handlebars.compile = function(string, compileOptions) { +Handlebars.compile = function(string, options) { + options = options || {}; + var compiled; - compileOptions = compileOptions || {}; + function compile() { + var ast = Handlebars.parse(string); + var environment = new Handlebars.Compiler().compile(ast, options); + var templateSpec = new Handlebars.JavaScriptCompiler().compile(environment, options, undefined, true); + return Handlebars.template(templateSpec); + } + // Template is only compiled on first use and cached after that point. return function(context, options) { if (!compiled) { - var ast = Handlebars.parse(string); - var environment = new Handlebars.Compiler().compile(ast, options); - var templateSpec = new Handlebars.JavaScriptCompiler().compile(environment, options, undefined, true); - compiled = Handlebars.template(templateSpec); + compiled = compile(); } return compiled.call(this, context, options); }; |