Treat partial exec in a manner closer to helpers
This helps unify the code handling and will also be needed to support string/id tracking on partials.
This commit is contained in:
@@ -275,7 +275,7 @@ JavaScriptCompiler.prototype = {
|
||||
blockValue: function(name) {
|
||||
var blockHelperMissing = this.aliasable('helpers.blockHelperMissing'),
|
||||
params = [this.contextName(0)];
|
||||
this.setupParams(name, 0, params);
|
||||
this.setupHelperArgs(name, 0, params);
|
||||
|
||||
var blockName = this.popStack();
|
||||
params.splice(1, 0, blockName);
|
||||
@@ -293,7 +293,7 @@ JavaScriptCompiler.prototype = {
|
||||
// We're being a bit cheeky and reusing the options value from the prior exec
|
||||
var blockHelperMissing = this.aliasable('helpers.blockHelperMissing'),
|
||||
params = [this.contextName(0)];
|
||||
this.setupParams('', 0, params, true);
|
||||
this.setupHelperArgs('', 0, params, true);
|
||||
|
||||
this.flushInline();
|
||||
|
||||
@@ -469,9 +469,7 @@ JavaScriptCompiler.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
emptyHash: function() {
|
||||
this.pushStackLiteral('{}');
|
||||
|
||||
emptyHash: function(omitEmpty) {
|
||||
if (this.trackIds) {
|
||||
this.push('{}'); // hashIds
|
||||
}
|
||||
@@ -479,6 +477,7 @@ JavaScriptCompiler.prototype = {
|
||||
this.push('{}'); // hashContexts
|
||||
this.push('{}'); // hashTypes
|
||||
}
|
||||
this.pushStackLiteral(omitEmpty ? 'undefined' : '{}');
|
||||
},
|
||||
pushHash: function() {
|
||||
if (this.hash) {
|
||||
@@ -611,16 +610,22 @@ JavaScriptCompiler.prototype = {
|
||||
// This operation pops off a context, invokes a partial with that context,
|
||||
// and pushes the result of the invocation back.
|
||||
invokePartial: function(name, indent) {
|
||||
var params = [this.nameLookup('partials', name, 'partial'), "'" + indent + "'", "'" + name + "'", this.popStack(), this.popStack(), "helpers", "partials"];
|
||||
var params = [],
|
||||
options = this.setupParams(name, 1, params, false);
|
||||
|
||||
if (this.options.data) {
|
||||
params.push("data");
|
||||
} else if (this.options.compat) {
|
||||
params.push('undefined');
|
||||
if (indent) {
|
||||
options.indent = JSON.stringify(indent);
|
||||
}
|
||||
options.helpers = 'helpers';
|
||||
options.partials = 'partials';
|
||||
|
||||
params.unshift(this.nameLookup('partials', name, 'partial'));
|
||||
|
||||
if (this.options.compat) {
|
||||
params.push('depths');
|
||||
options.depths = 'depths';
|
||||
}
|
||||
options = this.objectLiteral(options);
|
||||
params.push(options);
|
||||
|
||||
this.push(this.source.functionCall('this.invokePartial', '', params));
|
||||
},
|
||||
@@ -881,7 +886,7 @@ JavaScriptCompiler.prototype = {
|
||||
|
||||
setupHelper: function(paramSize, name, blockHelper) {
|
||||
var params = [],
|
||||
paramsInit = this.setupParams(name, paramSize, params, blockHelper);
|
||||
paramsInit = this.setupHelperArgs(name, paramSize, params, blockHelper);
|
||||
var foundHelper = this.nameLookup('helpers', name, 'helper');
|
||||
|
||||
return {
|
||||
@@ -892,8 +897,8 @@ JavaScriptCompiler.prototype = {
|
||||
};
|
||||
},
|
||||
|
||||
setupParams: function(helper, paramSize, params, useRegister) {
|
||||
var options = {}, contexts = [], types = [], ids = [], param, inverse, program;
|
||||
setupParams: function(helper, paramSize, params) {
|
||||
var options = {}, contexts = [], types = [], ids = [], param;
|
||||
|
||||
options.name = this.quotedString(helper);
|
||||
options.hash = this.popStack();
|
||||
@@ -906,8 +911,8 @@ JavaScriptCompiler.prototype = {
|
||||
options.hashContexts = this.popStack();
|
||||
}
|
||||
|
||||
inverse = this.popStack();
|
||||
program = this.popStack();
|
||||
var inverse = this.popStack(),
|
||||
program = this.popStack();
|
||||
|
||||
// Avoid setting fn and inverse if neither are set. This allows
|
||||
// helpers to do a check for `if (options.fn)`
|
||||
@@ -943,7 +948,11 @@ JavaScriptCompiler.prototype = {
|
||||
if (this.options.data) {
|
||||
options.data = "data";
|
||||
}
|
||||
return options;
|
||||
},
|
||||
|
||||
setupHelperArgs: function(helper, paramSize, params, useRegister) {
|
||||
var options = this.setupParams(helper, paramSize, params, true);
|
||||
options = this.objectLiteral(options);
|
||||
if (useRegister) {
|
||||
this.useRegister('options');
|
||||
|
||||
Reference in New Issue
Block a user