summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/ast.js
diff options
context:
space:
mode:
authorYehuda Katz <wycats@gmail.com>2012-05-28 00:15:52 -0700
committerYehuda Katz <wycats@gmail.com>2012-05-28 00:15:52 -0700
commit8786a6c6e23ec628300ab405fdec71a888eb39e6 (patch)
treec27d5b11d72b50e39415c63d829da4f4dc86a7d5 /lib/handlebars/compiler/ast.js
parent246325085faec21087ac177acfd9ce1492c88030 (diff)
downloadhandlebars.js-8786a6c6e23ec628300ab405fdec71a888eb39e6.zip
handlebars.js-8786a6c6e23ec628300ab405fdec71a888eb39e6.tar.gz
handlebars.js-8786a6c6e23ec628300ab405fdec71a888eb39e6.tar.bz2
Start doing earlier work on helpers
Diffstat (limited to 'lib/handlebars/compiler/ast.js')
-rw-r--r--lib/handlebars/compiler/ast.js27
1 files changed, 22 insertions, 5 deletions
diff --git a/lib/handlebars/compiler/ast.js b/lib/handlebars/compiler/ast.js
index cb238c0..47ecd35 100644
--- a/lib/handlebars/compiler/ast.js
+++ b/lib/handlebars/compiler/ast.js
@@ -11,12 +11,26 @@ var Handlebars = require('./base');
if(inverse) { this.inverse = new Handlebars.AST.ProgramNode(inverse); }
};
- Handlebars.AST.MustacheNode = function(params, hash, unescaped) {
+ Handlebars.AST.MustacheNode = function(rawParams, hash, unescaped) {
this.type = "mustache";
- this.id = params[0];
- this.params = params.slice(1);
- this.hash = hash;
this.escaped = !unescaped;
+ this.hash = hash;
+
+ var id = this.id = rawParams[0];
+ var params = this.params = rawParams.slice(1);
+
+ // a mustache is an eligible helper if:
+ // * its id is simple (a single part, not `this` or `..`)
+ var eligibleHelper = this.eligibleHelper = id.isSimple;
+
+ // a mustache is definitely a helper if:
+ // * it is an eligible helper, and
+ // * it has at least one parameter or hash segment
+ this.isHelper = eligibleHelper && (params.length || hash);
+
+ // if a mustache is an eligible helper but not a definite
+ // helper, it is ambiguous, and will be resolved in a later
+ // pass or at runtime.
};
Handlebars.AST.PartialNode = function(id, context) {
@@ -75,7 +89,10 @@ var Handlebars = require('./base');
this.parts = dig;
this.string = dig.join('.');
this.depth = depth;
- this.isSimple = (dig.length === 1) && (depth === 0);
+
+ // an ID is simple if it only has one part, and that part is not
+ // `..` or `this`.
+ this.isSimple = parts.length === 1 && !this.isScoped && depth === 0;
};
Handlebars.AST.StringNode = function(string) {