Pass container rather than exec as context
There is no real need for us to do `.call(container` other than for backwards compatibility with legacy versions. Using the 4.x release as a chance to optimize this behavior.
This commit is contained in:
@@ -20,7 +20,7 @@ JavaScriptCompiler.prototype = {
|
||||
}
|
||||
},
|
||||
depthedLookup: function(name) {
|
||||
return [this.aliasable('this.lookup'), '(depths, "', name, '")'];
|
||||
return [this.aliasable('container.lookup'), '(depths, "', name, '")'];
|
||||
},
|
||||
|
||||
compilerInfo: function() {
|
||||
@@ -189,7 +189,7 @@ JavaScriptCompiler.prototype = {
|
||||
}
|
||||
}
|
||||
|
||||
let params = ['depth0', 'helpers', 'partials', 'data'];
|
||||
let params = ['container', 'depth0', 'helpers', 'partials', 'data'];
|
||||
|
||||
if (this.useBlockParams || this.useDepths) {
|
||||
params.push('blockParams');
|
||||
@@ -359,7 +359,7 @@ JavaScriptCompiler.prototype = {
|
||||
// Escape `value` and append it to the buffer
|
||||
appendEscaped: function() {
|
||||
this.pushSource(this.appendToBuffer(
|
||||
[this.aliasable('this.escapeExpression'), '(', this.popStack(), ')']));
|
||||
[this.aliasable('container.escapeExpression'), '(', this.popStack(), ')']));
|
||||
},
|
||||
|
||||
// [getContext]
|
||||
@@ -428,7 +428,7 @@ JavaScriptCompiler.prototype = {
|
||||
if (!depth) {
|
||||
this.pushStackLiteral('data');
|
||||
} else {
|
||||
this.pushStackLiteral('this.data(data, ' + depth + ')');
|
||||
this.pushStackLiteral('container.data(data, ' + depth + ')');
|
||||
}
|
||||
|
||||
this.resolvePath('data', parts, 0, true, strict);
|
||||
@@ -466,7 +466,7 @@ JavaScriptCompiler.prototype = {
|
||||
// If the `value` is a lambda, replace it on the stack by
|
||||
// the return value of the lambda
|
||||
resolvePossibleLambda: function() {
|
||||
this.push([this.aliasable('this.lambda'), '(', this.popStack(), ', ', this.contextName(0), ')']);
|
||||
this.push([this.aliasable('container.lambda'), '(', this.popStack(), ', ', this.contextName(0), ')']);
|
||||
},
|
||||
|
||||
// [pushStringParam]
|
||||
@@ -669,7 +669,7 @@ JavaScriptCompiler.prototype = {
|
||||
options = this.objectLiteral(options);
|
||||
params.push(options);
|
||||
|
||||
this.push(this.source.functionCall('this.invokePartial', '', params));
|
||||
this.push(this.source.functionCall('container.invokePartial', '', params));
|
||||
},
|
||||
|
||||
// [assignToHash]
|
||||
@@ -771,7 +771,7 @@ JavaScriptCompiler.prototype = {
|
||||
programParams.push('depths');
|
||||
}
|
||||
|
||||
return 'this.program(' + programParams.join(', ') + ')';
|
||||
return 'container.program(' + programParams.join(', ') + ')';
|
||||
},
|
||||
|
||||
useRegister: function(name) {
|
||||
@@ -965,8 +965,8 @@ JavaScriptCompiler.prototype = {
|
||||
// Avoid setting fn and inverse if neither are set. This allows
|
||||
// helpers to do a check for `if (options.fn)`
|
||||
if (program || inverse) {
|
||||
options.fn = program || 'this.noop';
|
||||
options.inverse = inverse || 'this.noop';
|
||||
options.fn = program || 'container.noop';
|
||||
options.inverse = inverse || 'container.noop';
|
||||
}
|
||||
|
||||
// The parameters go on to the stack in order (making sure that they are evaluated in order)
|
||||
@@ -1061,7 +1061,7 @@ function strictLookup(requireTerminal, compiler, parts, type) {
|
||||
}
|
||||
|
||||
if (requireTerminal) {
|
||||
return [compiler.aliasable('this.strict'), '(', stack, ', ', compiler.quotedString(parts[i]), ')'];
|
||||
return [compiler.aliasable('container.strict'), '(', stack, ', ', compiler.quotedString(parts[i]), ')'];
|
||||
} else {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ export function template(templateSpec, env) {
|
||||
}
|
||||
}
|
||||
|
||||
return '' + templateSpec.main.call(container, context, container.helpers, container.partials, data, blockParams, depths);
|
||||
return '' + templateSpec.main(container, context, container.helpers, container.partials, data, blockParams, depths);
|
||||
}
|
||||
ret.isTop = true;
|
||||
|
||||
@@ -179,7 +179,7 @@ export function wrapProgram(container, i, fn, data, declaredBlockParams, blockPa
|
||||
currentDepths = [context].concat(depths);
|
||||
}
|
||||
|
||||
return fn.call(container,
|
||||
return fn(container,
|
||||
context,
|
||||
container.helpers, container.partials,
|
||||
options.data || data,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
define(['handlebars.runtime'], function(Handlebars) {
|
||||
Handlebars = Handlebars["default"]; var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
|
||||
return templates['empty'] = template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
|
||||
return templates['empty'] = template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(container,depth0,helpers,partials,data) {
|
||||
return "";
|
||||
},"useData":true});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user