diff options
author | kpdecker <kpdecker@gmail.com> | 2011-07-31 14:10:32 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2011-07-31 14:10:32 -0500 |
commit | 9821da8df7b80a60cd2a0cc96804fc7ce598c70f (patch) | |
tree | 6a02afcd4ced846c4a22d2265f6764993e195a80 /lib/handlebars/compiler/compiler.js | |
parent | 2d538baf726f2b2da0c8e35956416e2946c88997 (diff) | |
download | handlebars.js-9821da8df7b80a60cd2a0cc96804fc7ce598c70f.zip handlebars.js-9821da8df7b80a60cd2a0cc96804fc7ce598c70f.tar.gz handlebars.js-9821da8df7b80a60cd2a0cc96804fc7ce598c70f.tar.bz2 |
Move aliases and registers into context object.
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 613fbd3..554a393 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -319,12 +319,15 @@ Handlebars.JavaScriptCompiler = function() {}; this.environment = environment; this.options = options || {}; + this.context = { + aliases: {}, + registers: {list: []} + }; + this.preamble(); this.stackSlot = 0; this.stackVars = []; - this.aliases = {}; - this.registers = {list: []}; this.compileChildren(environment, options, asObject); @@ -380,7 +383,7 @@ Handlebars.JavaScriptCompiler = function() {}; if(this.environment.usePartial) { copies = copies + " partials = partials || Handlebars.partials;"; } out.push(copies); - out.push("var buffer = " + this.initializeBuffer() + ", currentContext = context, execRef"); + out.push("var buffer = " + this.initializeBuffer() + ", currentContext = context"); // track the last context pushed into place to allow skipping the // getContext opcode when it would be a noop @@ -389,7 +392,7 @@ Handlebars.JavaScriptCompiler = function() {}; }, createFunctionContext: function(asObject) { - var locals = this.stackVars.concat(this.registers.list); + var locals = this.stackVars.concat(this.context.registers.list); if(locals.length > 0) { this.source[1] = this.source[1] + ", " + locals.join(", "); @@ -397,8 +400,8 @@ Handlebars.JavaScriptCompiler = function() {}; // Generate minimizer alias mappings var aliases = [] - for (var alias in this.aliases) { - this.source[1] = this.source[1] + ', ' + alias + '=' + this.aliases[alias]; + for (var alias in this.context.aliases) { + this.source[1] = this.source[1] + ', ' + alias + '=' + this.context.aliases[alias]; } this.source[1] = this.source[1] + ";"; @@ -450,7 +453,7 @@ Handlebars.JavaScriptCompiler = function() {}; appendEscaped: function() { var opcode = this.nextOpcode(1), extra = ""; - this.aliases.escapeExpression = 'this.escapeExpression'; + this.context.aliases.escapeExpression = 'this.escapeExpression'; if(opcode[0] === 'appendContent') { extra = " + " + this.quotedString(opcode[1][0]); @@ -513,8 +516,8 @@ Handlebars.JavaScriptCompiler = function() {}; invokeMustache: function(paramSize, original) { this.populateParams(paramSize, this.quotedString(original), "{}", null, function(nextStack, helperMissingString, id) { - this.aliases.helperMissing = 'helpers.helperMissing'; - this.aliases.undef = 'void 0'; + this.context.aliases.helperMissing = 'helpers.helperMissing'; + this.context.aliases.undef = 'void 0'; this.source.push("else if(" + id + "=== undef) { " + nextStack + " = helperMissing.call(" + helperMissingString + "); }"); this.source.push("else { " + nextStack + " = " + id + "; }"); }); @@ -525,7 +528,7 @@ Handlebars.JavaScriptCompiler = function() {}; var mainProgram = this.programExpression(guid); this.populateParams(paramSize, null, mainProgram, inverse, function(nextStack, helperMissingString, id) { - this.aliases.blockHelperMissing = 'helpers.blockHelperMissing'; + this.context.aliases.blockHelperMissing = 'helpers.blockHelperMissing'; this.source.push("else { " + nextStack + " = blockHelperMissing.call(" + helperMissingString + "); }"); }); }, @@ -572,7 +575,7 @@ Handlebars.JavaScriptCompiler = function() {}; var nextStack = this.nextStack(); - this.aliases.functionType = '"function"'; + this.context.aliases.functionType = '"function"'; this.source.push("if(typeof " + id + " === functionType) { " + nextStack + " = " + id + ".call(" + paramString + "); }"); fn.call(this, nextStack, helperMissingString, id); }, @@ -645,9 +648,9 @@ Handlebars.JavaScriptCompiler = function() {}; }, useRegister: function(name) { - if(!this.registers[name]) { - this.registers[name] = true; - this.registers.list.push(name); + if(!this.context.registers[name]) { + this.context.registers[name] = true; + this.context.registers.list.push(name); } }, |