diff --git a/lib/handlebars/vm.js b/lib/handlebars/vm.js index 10d8df24..3dbd8f45 100644 --- a/lib/handlebars/vm.js +++ b/lib/handlebars/vm.js @@ -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; } };