Make the Handlebars environment into an object
The idea is that the environment wraps up the mutable stuff in Handlebars (like the helpers) and that you could theoretically create a new one at any time and pass it in to Handlebars.template. Every test makes a new environment and uses it in template compilation.
This commit is contained in:
@@ -443,17 +443,17 @@ export function compile(input, options) {
|
||||
|
||||
var compiled;
|
||||
|
||||
function compile() {
|
||||
function compileInput() {
|
||||
var ast = parse(input);
|
||||
var environment = new Compiler().compile(ast, options);
|
||||
var templateSpec = new JavaScriptCompiler().compile(environment, options, undefined, true);
|
||||
return template(templateSpec);
|
||||
return template(templateSpec, options.env || Handlebars, compile);
|
||||
}
|
||||
|
||||
// Template is only compiled on first use and cached after that point.
|
||||
return function(context, options) {
|
||||
if (!compiled) {
|
||||
compiled = compile();
|
||||
compiled = compileInput();
|
||||
}
|
||||
return compiled.call(this, context, options);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user