Phase 2 of precompiled extraction:

Use string representations to pass around the function context
This commit is contained in:
kpdecker
2011-07-30 11:23:24 -05:00
parent 74bd8cac60
commit 59f5331db4
2 changed files with 12 additions and 9 deletions
+10 -8
View File
@@ -409,17 +409,19 @@ Handlebars.JavaScriptCompiler = function() {};
if(params.length === 4 && !this.environment.usePartial) { params.pop(); }
params.push(this.source.join("\n"));
var functionSource = 'function(' + params.join(',') + ') {\n ' + this.source.join("\n ") + '}';
var fn = Function.apply(this, params);
fn.displayName = "Handlebars.js";
Handlebars.log(Handlebars.logger.DEBUG, functionSource + "\n\n");
Handlebars.log(Handlebars.logger.DEBUG, fn.toString() + "\n\n");
var script = ['{\n fn: ', functionSource, ',\n children: [\n '],
children = this.environment.children;
for (var i = 0, len = children.length; i < len; i++) {
script.push(children[i]);
if (i < len-1) { script.push(',\n'); }
}
script.push('\n ]\n}');
return {
fn: fn,
children: this.environment.children
};
return script.join('');
},
appendContent: function(content) {
+2 -1
View File
@@ -69,7 +69,8 @@ Handlebars.VM = {
compile: function(string, options) {
var ast = Handlebars.parse(string);
var environment = new Handlebars.Compiler().compile(ast, options);
var logic = new Handlebars.JavaScriptCompiler().compile(environment, options);
// Yes this is evil. Work in progress for the best way to handle runtime comp vs. cached comp.
var logic = eval('(' + new Handlebars.JavaScriptCompiler().compile(environment, options) + ')');
return Handlebars.VM.generateContainer(logic);
},
invokePartial: function(partial, name, context, helpers, partials) {