Handlebars.parse/precompile/compile can now be passed an already-compiled Handlebars AST.
This commit is contained in:
@@ -1221,23 +1221,23 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
|
||||
})(Handlebars.Compiler, Handlebars.JavaScriptCompiler);
|
||||
|
||||
Handlebars.precompile = function(string, options) {
|
||||
if (typeof string !== 'string') {
|
||||
throw new Handlebars.Exception("You must pass a string to Handlebars.compile. You passed " + string);
|
||||
Handlebars.precompile = function(input, options) {
|
||||
if (!input || (typeof input !== 'string' && input.constructor !== Handlebars.AST.ProgramNode)) {
|
||||
throw new Handlebars.Exception("You must pass a string or Handlebars AST to Handlebars.compile. You passed " + input);
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
if (!('data' in options)) {
|
||||
options.data = true;
|
||||
}
|
||||
var ast = Handlebars.parse(string);
|
||||
var ast = Handlebars.parse(input);
|
||||
var environment = new Handlebars.Compiler().compile(ast, options);
|
||||
return new Handlebars.JavaScriptCompiler().compile(environment, options);
|
||||
};
|
||||
|
||||
Handlebars.compile = function(string, options) {
|
||||
if (typeof string !== 'string') {
|
||||
throw new Handlebars.Exception("You must pass a string to Handlebars.compile. You passed " + string);
|
||||
Handlebars.compile = function(input, options) {
|
||||
if (!input || (typeof input !== 'string' && input.constructor !== Handlebars.AST.ProgramNode)) {
|
||||
throw new Handlebars.Exception("You must pass a string or Handlebars AST to Handlebars.compile. You passed " + input);
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
@@ -1246,7 +1246,7 @@ Handlebars.compile = function(string, options) {
|
||||
}
|
||||
var compiled;
|
||||
function compile() {
|
||||
var ast = Handlebars.parse(string);
|
||||
var ast = Handlebars.parse(input);
|
||||
var environment = new Handlebars.Compiler().compile(ast, options);
|
||||
var templateSpec = new Handlebars.JavaScriptCompiler().compile(environment, options, undefined, true);
|
||||
return Handlebars.template(templateSpec);
|
||||
|
||||
Reference in New Issue
Block a user