Permalink
Browse files

Add program metadata

Include program id and depth on the generated wrapper objects. This
allows helpers who are passed these objects to differentiate between
helpers for cases where they may want to cache the generated DOM
structure.
  • Loading branch information...
kpdecker committed Feb 17, 2013
1 parent c95b3d6 commit baccdb4cfc241cbcfd02d21aada56100c6c9c132
Showing with 19 additions and 19 deletions.
  1. +3 −2 lib/handlebars/base.js
  2. +1 −6 lib/handlebars/compiler/compiler.js
  3. +15 −11 lib/handlebars/runtime.js
View
@@ -7,11 +7,12 @@ var Handlebars = {};
// BEGIN(BROWSER)
Handlebars.VERSION = "1.0.0-rc.3";
-Handlebars.COMPILER_REVISION = 2;
+Handlebars.COMPILER_REVISION = 3;
Handlebars.REVISION_CHANGES = {
1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
- 2: '>= 1.0.0-rc.3'
+ 2: '== 1.0.0-rc.3',
+ 3: '>= 1.0.0-rc.4'
};
Handlebars.helpers = {};
@@ -993,12 +993,7 @@ JavaScriptCompiler.prototype = {
else { programParams.push("depth" + (depth - 1)); }
}
- if(depths.length === 0) {
- return "self.program(" + programParams.join(", ") + ")";
- } else {
- programParams.shift();
- return "self.programWithDepth(" + programParams.join(", ") + ")";
- }
+ return (depths.length === 0 ? "self.program(" : "self.programWithDepth(") + programParams.join(", ") + ")";
},
register: function(name, val) {
View
@@ -12,13 +12,11 @@ Handlebars.VM = {
program: function(i, fn, data) {
var programWrapper = this.programs[i];
if(data) {
- return Handlebars.VM.program(fn, data);
- } else if(programWrapper) {
- return programWrapper;
- } else {
- programWrapper = this.programs[i] = Handlebars.VM.program(fn);
- return programWrapper;
+ programWrapper = Handlebars.VM.program(i, fn, data);
+ } else if (!programWrapper) {
+ programWrapper = this.programs[i] = Handlebars.VM.program(i, fn);
}
+ return programWrapper;
},
programWithDepth: Handlebars.VM.programWithDepth,
noop: Handlebars.VM.noop,
@@ -50,21 +48,27 @@ Handlebars.VM = {
};
},
- programWithDepth: function(fn, data, $depth) {
- var args = Array.prototype.slice.call(arguments, 2);
+ programWithDepth: function(i, fn, data /*, $depth */) {
+ var args = Array.prototype.slice.call(arguments, 3);
- return function(context, options) {
+ var program = function(context, options) {
options = options || {};
return fn.apply(this, [context, options.data || data].concat(args));
};
+ program.program = i;
+ program.depth = args.length;
+ return program;
},
- program: function(fn, data) {
- return function(context, options) {
+ program: function(i, fn, data) {
+ var program = function(context, options) {
options = options || {};
return fn(context, options.data || data);
};
+ program.program = i;
+ program.depth = 0;
+ return program;
},
noop: function() { return ""; },
invokePartial: function(partial, name, context, helpers, partials, data) {

1 comment on commit baccdb4

mixonic commented on baccdb4 May 1, 2013

Ember throws a misleading error if you use a build of Handlebars made after this commit. I've opened a PR to improve the error message: emberjs/ember.js#2602

Please sign in to comment.