summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/ast.js
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2014-12-21 22:32:50 -0600
committerkpdecker <kpdecker@gmail.com>2014-12-21 22:32:50 -0600
commit9e907e67854ea1ae208fe061452a9c9e2ce9468b (patch)
tree48840a49d3dc79b549615f2a7344f8b5ecc50de4 /lib/handlebars/compiler/ast.js
parent6d2239d8ac471d05086026e2bd622f879ccde52b (diff)
downloadhandlebars.js-9e907e67854ea1ae208fe061452a9c9e2ce9468b.zip
handlebars.js-9e907e67854ea1ae208fe061452a9c9e2ce9468b.tar.gz
handlebars.js-9e907e67854ea1ae208fe061452a9c9e2ce9468b.tar.bz2
Expose AST helpers in public API
Diffstat (limited to 'lib/handlebars/compiler/ast.js')
-rw-r--r--lib/handlebars/compiler/ast.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/handlebars/compiler/ast.js b/lib/handlebars/compiler/ast.js
index 3f4639c..113c03e 100644
--- a/lib/handlebars/compiler/ast.js
+++ b/lib/handlebars/compiler/ast.js
@@ -104,6 +104,27 @@ var AST = {
this.type = 'HashPair';
this.key = key;
this.value = value;
+ },
+
+ // Public API used to evaluate derived attributes regarding AST nodes
+ helpers: {
+ // a mustache is definitely a helper if:
+ // * it is an eligible helper, and
+ // * it has at least one parameter or hash segment
+ // TODO: Make these public utility methods
+ helperExpression: function(sexpr) {
+ return !!(sexpr.isHelper || sexpr.params.length || sexpr.hash);
+ },
+
+ scopedId: function(path) {
+ return (/^\.|this\b/).test(path.original);
+ },
+
+ // an ID is simple if it only has one part, and that part is not
+ // `..` or `this`.
+ simpleId: function(path) {
+ return path.parts.length === 1 && !AST.helpers.scopedId(path) && !path.depth;
+ }
}
};