summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/compiler.js
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2015-01-18 17:27:27 -0600
committerkpdecker <kpdecker@gmail.com>2015-01-18 17:27:27 -0600
commit884bf1553663734f22ffcd9d758c9d71d4373bf9 (patch)
tree55d078077b9c23779858282dfe42dd3a42bd7c0d /lib/handlebars/compiler/compiler.js
parent999da739a66199483ffc4d82426550aee5ac798f (diff)
downloadhandlebars.js-884bf1553663734f22ffcd9d758c9d71d4373bf9.zip
handlebars.js-884bf1553663734f22ffcd9d758c9d71d4373bf9.tar.gz
handlebars.js-884bf1553663734f22ffcd9d758c9d71d4373bf9.tar.bz2
Avoid direct references to sexpr in statements
This allows us to avoid creating unnecessary AST nodes and avoids things like isHelper. Side effect of these changes is that @data functions can now have data parameters passed to them.
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r--lib/handlebars/compiler/compiler.js30
1 files changed, 12 insertions, 18 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js
index 524f9aa..03bf8f4 100644
--- a/lib/handlebars/compiler/compiler.js
+++ b/lib/handlebars/compiler/compiler.js
@@ -110,28 +110,27 @@ Compiler.prototype = {
},
BlockStatement: function(block) {
- var sexpr = block.sexpr,
- program = block.program,
+ var program = block.program,
inverse = block.inverse;
program = program && this.compileProgram(program);
inverse = inverse && this.compileProgram(inverse);
- var type = this.classifySexpr(sexpr);
+ var type = this.classifySexpr(block);
if (type === 'helper') {
- this.helperSexpr(sexpr, program, inverse);
+ this.helperSexpr(block, program, inverse);
} else if (type === 'simple') {
- this.simpleSexpr(sexpr);
+ this.simpleSexpr(block);
// now that the simple mustache is resolved, we need to
// evaluate it by executing `blockHelperMissing`
this.opcode('pushProgram', program);
this.opcode('pushProgram', inverse);
this.opcode('emptyHash');
- this.opcode('blockValue', sexpr.path.original);
+ this.opcode('blockValue', block.path.original);
} else {
- this.ambiguousSexpr(sexpr, program, inverse);
+ this.ambiguousSexpr(block, program, inverse);
// now that the simple mustache is resolved, we need to
// evaluate it by executing `blockHelperMissing`
@@ -147,20 +146,20 @@ Compiler.prototype = {
PartialStatement: function(partial) {
this.usePartial = true;
- var params = partial.sexpr.params;
+ var params = partial.params;
if (params.length > 1) {
throw new Exception('Unsupported number of partial arguments: ' + params.length, partial);
} else if (!params.length) {
params.push({type: 'PathExpression', parts: [], depth: 0});
}
- var partialName = partial.sexpr.name.original,
- isDynamic = partial.sexpr.name.type === 'SubExpression';
+ var partialName = partial.name.original,
+ isDynamic = partial.name.type === 'SubExpression';
if (isDynamic) {
- this.accept(partial.sexpr.name);
+ this.accept(partial.name);
}
- this.setupFullMustacheParams(partial.sexpr, undefined, undefined, true);
+ this.setupFullMustacheParams(partial, undefined, undefined, true);
var indent = partial.indent || '';
if (this.options.preventIndent && indent) {
@@ -173,7 +172,7 @@ Compiler.prototype = {
},
MustacheStatement: function(mustache) {
- this.accept(mustache.sexpr);
+ this.SubExpression(mustache);
if(mustache.escaped && !this.options.noEscape) {
this.opcode('appendEscaped');
@@ -340,11 +339,6 @@ Compiler.prototype = {
pushParam: function(val) {
var value = val.value != null ? val.value : val.original || '';
- // Force helper evaluation
- if (val.type === 'SubExpression') {
- val.isHelper = true;
- }
-
if (this.stringParams) {
if (value.replace) {
value = value