summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/compiler.js
diff options
context:
space:
mode:
authortomhuda <tomhuda@tilde.io>2012-07-12 10:07:10 -0700
committertomhuda <tomhuda@tilde.io>2012-07-12 10:07:10 -0700
commitf79af6bfa3081187907c2615ddc3708915b5e44c (patch)
tree6dea69aaece417a85ab6445a32671d3119883423 /lib/handlebars/compiler/compiler.js
parent92b6c1401a95a1550524d264b1e5f4494f9a587f (diff)
parentefb1e25690e5c05b1d1662d72cac31f3cb90b67f (diff)
downloadhandlebars.js-f79af6bfa3081187907c2615ddc3708915b5e44c.zip
handlebars.js-f79af6bfa3081187907c2615ddc3708915b5e44c.tar.gz
handlebars.js-f79af6bfa3081187907c2615ddc3708915b5e44c.tar.bz2
Merge branch 'master' of github.com:wycats/handlebars.js
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r--lib/handlebars/compiler/compiler.js35
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: ...