DRY up some code that converts program AST nodes to opcodes.
This commit is contained in:
+20
-25
@@ -135,26 +135,14 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
|
||||
block: function(block) {
|
||||
var mustache = block.mustache;
|
||||
var params = mustache.params, depth, child, inverse, inverseGuid;
|
||||
var depth, child, inverse, inverseGuid;
|
||||
|
||||
this.pushParams(params);
|
||||
|
||||
if(mustache.hash) {
|
||||
this.hash(mustache.hash);
|
||||
} else {
|
||||
this.opcode('push', '{}');
|
||||
}
|
||||
|
||||
// ID lookup is now on the stack
|
||||
this.ID(mustache.id);
|
||||
var params = this.setupStackForMustache(mustache);
|
||||
|
||||
var programGuid = this.compileProgram(block.program);
|
||||
|
||||
if(block.program.inverse) {
|
||||
inverseGuid = this.compileProgram(block.program.inverse);
|
||||
}
|
||||
|
||||
if(block.program.inverse) {
|
||||
this.declare('inverse', inverseGuid);
|
||||
}
|
||||
|
||||
@@ -204,17 +192,7 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
},
|
||||
|
||||
mustache: function(mustache) {
|
||||
var params = mustache.params;
|
||||
|
||||
this.pushParams(params);
|
||||
|
||||
if(mustache.hash) {
|
||||
this.hash(mustache.hash);
|
||||
} else {
|
||||
this.opcode('push', '{}');
|
||||
}
|
||||
|
||||
this.ID(mustache.id);
|
||||
var params = this.setupStackForMustache(mustache);
|
||||
|
||||
this.opcode('invokeMustache', params.length, mustache.id.original);
|
||||
|
||||
@@ -243,6 +221,7 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
|
||||
comment: function() {},
|
||||
|
||||
// HELPERS
|
||||
pushParams: function(params) {
|
||||
var i = params.length, param;
|
||||
|
||||
@@ -271,6 +250,22 @@ Handlebars.JavaScriptCompiler = function() {};
|
||||
this.depths[depth] = true;
|
||||
this.depths.list.push(depth);
|
||||
}
|
||||
},
|
||||
|
||||
setupStackForMustache: function(mustache) {
|
||||
var params = mustache.params;
|
||||
|
||||
this.pushParams(params);
|
||||
|
||||
if(mustache.hash) {
|
||||
this.hash(mustache.hash);
|
||||
} else {
|
||||
this.opcode('push', '{}');
|
||||
}
|
||||
|
||||
this.ID(mustache.id);
|
||||
|
||||
return params;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user