diff options
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 20a558d..ca59725 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -210,17 +210,17 @@ Handlebars.JavaScriptCompiler = function() {}; simpleMustache: function(mustache, program, inverse) { var id = mustache.id; - this.addDepth(id.depth); - this.opcode('getContext', id.depth); - - if (id.parts.length) { - this.opcode('lookupOnContext', id.parts[0]); - for(var i=1, l=id.parts.length; i<l; i++) { - this.opcode('lookup', id.parts[i]); - } + if (id.type === 'DATA') { + this.DATA(id); + } else if (id.parts.length) { + this.ID(id); } else { + // Simplified ID for `this` + this.addDepth(id.depth); + this.opcode('getContext', id.depth); this.opcode('pushContext'); } + this.opcode('resolvePossibleLambda'); }, @@ -247,6 +247,11 @@ Handlebars.JavaScriptCompiler = function() {}; } }, + DATA: function(data) { + this.options.data = true; + this.opcode('lookupData', data.id); + }, + STRING: function(string) { this.opcode('pushString', string.string); }, @@ -271,6 +276,7 @@ Handlebars.JavaScriptCompiler = function() {}; }, addDepth: function(depth) { + if(isNaN(depth)) { throw new Error("EWOT"); } if(depth === 0) { return; } if(!this.depths[depth]) { @@ -437,7 +443,8 @@ Handlebars.JavaScriptCompiler = function() {}; if (!this.isChild) { var namespace = this.namespace; var copies = "helpers = helpers || " + namespace + ".helpers;"; - if(this.environment.usePartial) { copies = copies + " partials = partials || " + namespace + ".partials;"; } + if (this.environment.usePartial) { copies = copies + " partials = partials || " + namespace + ".partials;"; } + if (this.options.data) { copies = copies + " data = data || {};"; } out.push(copies); } else { out.push(''); @@ -646,6 +653,16 @@ Handlebars.JavaScriptCompiler = function() {}; }); }, + // [lookupData] + // + // On stack, before: ... + // On stack, after: data[id], ... + // + // Push the result of looking up `id` on the current data + lookupData: function(id) { + this.pushStack(this.nameLookup('data', id, 'data')); + }, + // [pushStringParam] // // On stack, before: ... |