diff options
author | Yehuda Katz <wycats@gmail.com> | 2012-07-05 22:43:05 -0700 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2012-07-05 22:43:05 -0700 |
commit | 72e05d623c07cc3a812528d52fb6d325134efee4 (patch) | |
tree | 8eec0d2b12cb9faaeea22a76fd0c045457669f7c /lib/handlebars/compiler/compiler.js | |
parent | ff1547ea049e5b4b499dfa8d4d450567a91f5505 (diff) | |
download | handlebars.js-72e05d623c07cc3a812528d52fb6d325134efee4.zip handlebars.js-72e05d623c07cc3a812528d52fb6d325134efee4.tar.gz handlebars.js-72e05d623c07cc3a812528d52fb6d325134efee4.tar.bz2 |
Add support for @data variables
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 6807494..ae48c69 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -96,7 +96,7 @@ Handlebars.JavaScriptCompiler = function() {}; this.children[guid] = result; for(var i=0, l=result.depths.list.length; i<l; i++) { - var depth = result.depths.list[i]; + depth = result.depths.list[i]; if(depth < 2) { continue; } else { this.addDepth(depth - 1); } @@ -210,10 +210,14 @@ Handlebars.JavaScriptCompiler = function() {}; simpleMustache: function(mustache, program, inverse) { var id = mustache.id; - this.addDepth(id.depth); - this.opcode('getContext', id.depth); + if (id.type === 'ID') { + this.addDepth(id.depth); + this.opcode('getContext', id.depth); + } - if (id.parts.length) { + if (id.type === 'DATA') { + this.opcode('lookupData', id.id); + } else 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]); @@ -247,6 +251,10 @@ Handlebars.JavaScriptCompiler = function() {}; } }, + DATA: function(data) { + this.opcode('lookupData', data.id); + }, + STRING: function(string) { this.opcode('pushString', string.string); }, @@ -271,6 +279,7 @@ Handlebars.JavaScriptCompiler = function() {}; }, addDepth: function(depth) { + if(isNaN(depth)) { throw new Error("EWOT"); } if(depth === 0) { return; } if(!this.depths[depth]) { @@ -646,6 +655,10 @@ Handlebars.JavaScriptCompiler = function() {}; }); }, + lookupData: function(id) { + this.pushStack(this.nameLookup('data', id, 'data')); + }, + // [pushStringParam] // // On stack, before: ... @@ -831,7 +844,7 @@ Handlebars.JavaScriptCompiler = function() {}; var programParams = [child.index, child.name, "data"]; for(var i=0, l = depths.length; i<l; i++) { - var depth = depths[i]; + depth = depths[i]; if(depth === 1) { programParams.push("depth0"); } else { programParams.push("depth" + (depth - 1)); } |