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) {
|
block: function(block) {
|
||||||
var mustache = block.mustache;
|
var mustache = block.mustache;
|
||||||
var params = mustache.params, depth, child, inverse, inverseGuid;
|
var depth, child, inverse, inverseGuid;
|
||||||
|
|
||||||
this.pushParams(params);
|
var params = this.setupStackForMustache(mustache);
|
||||||
|
|
||||||
if(mustache.hash) {
|
|
||||||
this.hash(mustache.hash);
|
|
||||||
} else {
|
|
||||||
this.opcode('push', '{}');
|
|
||||||
}
|
|
||||||
|
|
||||||
// ID lookup is now on the stack
|
|
||||||
this.ID(mustache.id);
|
|
||||||
|
|
||||||
var programGuid = this.compileProgram(block.program);
|
var programGuid = this.compileProgram(block.program);
|
||||||
|
|
||||||
if(block.program.inverse) {
|
if(block.program.inverse) {
|
||||||
inverseGuid = this.compileProgram(block.program.inverse);
|
inverseGuid = this.compileProgram(block.program.inverse);
|
||||||
}
|
|
||||||
|
|
||||||
if(block.program.inverse) {
|
|
||||||
this.declare('inverse', inverseGuid);
|
this.declare('inverse', inverseGuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,17 +192,7 @@ Handlebars.JavaScriptCompiler = function() {};
|
|||||||
},
|
},
|
||||||
|
|
||||||
mustache: function(mustache) {
|
mustache: function(mustache) {
|
||||||
var params = mustache.params;
|
var params = this.setupStackForMustache(mustache);
|
||||||
|
|
||||||
this.pushParams(params);
|
|
||||||
|
|
||||||
if(mustache.hash) {
|
|
||||||
this.hash(mustache.hash);
|
|
||||||
} else {
|
|
||||||
this.opcode('push', '{}');
|
|
||||||
}
|
|
||||||
|
|
||||||
this.ID(mustache.id);
|
|
||||||
|
|
||||||
this.opcode('invokeMustache', params.length, mustache.id.original);
|
this.opcode('invokeMustache', params.length, mustache.id.original);
|
||||||
|
|
||||||
@@ -243,6 +221,7 @@ Handlebars.JavaScriptCompiler = function() {};
|
|||||||
|
|
||||||
comment: function() {},
|
comment: function() {},
|
||||||
|
|
||||||
|
// HELPERS
|
||||||
pushParams: function(params) {
|
pushParams: function(params) {
|
||||||
var i = params.length, param;
|
var i = params.length, param;
|
||||||
|
|
||||||
@@ -271,6 +250,22 @@ Handlebars.JavaScriptCompiler = function() {};
|
|||||||
this.depths[depth] = true;
|
this.depths[depth] = true;
|
||||||
this.depths.list.push(depth);
|
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