summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'lib/handlebars/compiler')
-rw-r--r--lib/handlebars/compiler/ast.js47
-rw-r--r--lib/handlebars/compiler/helpers.js37
2 files changed, 46 insertions, 38 deletions
diff --git a/lib/handlebars/compiler/ast.js b/lib/handlebars/compiler/ast.js
index efb4ece..9f25443 100644
--- a/lib/handlebars/compiler/ast.js
+++ b/lib/handlebars/compiler/ast.js
@@ -10,20 +10,12 @@ var AST = {
this.strip = strip;
},
- MustacheStatement: function(rawParams, open, strip, locInfo) {
+ MustacheStatement: function(sexpr, escaped, strip, locInfo) {
this.loc = locInfo;
this.type = 'MustacheStatement';
- this.sexpr = rawParams;
-
- // Open may be a string parsed from the parser or a passed boolean flag
- if (open != null && open.charAt) {
- // Must use charAt to support IE pre-10
- var escapeFlag = open.charAt(3) || open.charAt(2);
- this.escaped = escapeFlag !== '{' && escapeFlag !== '&';
- } else {
- this.escaped = !!open;
- }
+ this.sexpr = sexpr;
+ this.escaped = escaped;
this.strip = strip;
},
@@ -63,43 +55,22 @@ var AST = {
strip.inlineStandalone = true;
},
- SubExpression: function(rawParams, hash, locInfo) {
+ SubExpression: function(path, params, hash, locInfo) {
this.loc = locInfo;
this.type = 'SubExpression';
- this.path = rawParams[0];
- this.params = rawParams.slice(1);
+ this.path = path;
+ this.params = params || [];
this.hash = hash;
},
- PathExpression: function(data, parts, locInfo) {
+ PathExpression: function(data, depth, parts, original, locInfo) {
this.loc = locInfo;
this.type = 'PathExpression';
- var original = '',
- dig = [],
- depth = 0,
- depthString = '';
-
- for(var i=0,l=parts.length; i<l; i++) {
- var part = parts[i].part;
- original += (parts[i].separator || '') + part;
-
- if (part === '..' || part === '.' || part === 'this') {
- if (dig.length > 0) {
- throw new Exception('Invalid path: ' + original, this);
- } else if (part === '..') {
- depth++;
- depthString += '../';
- }
- } else {
- dig.push(part);
- }
- }
-
this.data = data;
- this.original = (data ? '@' : '') + original;
- this.parts = dig;
+ this.original = original;
+ this.parts = parts;
this.depth = depth;
},
diff --git a/lib/handlebars/compiler/helpers.js b/lib/handlebars/compiler/helpers.js
index 3d5144f..f215049 100644
--- a/lib/handlebars/compiler/helpers.js
+++ b/lib/handlebars/compiler/helpers.js
@@ -24,6 +24,43 @@ export function stripComment(comment) {
.replace(/-?-?~?\}\}$/, '');
}
+export function preparePath(data, parts, locInfo) {
+ /*jshint -W040 */
+ locInfo = this.locInfo(locInfo);
+
+ var original = data ? '@' : '',
+ dig = [],
+ depth = 0,
+ depthString = '';
+
+ for(var i=0,l=parts.length; i<l; i++) {
+ var part = parts[i].part;
+ original += (parts[i].separator || '') + part;
+
+ if (part === '..' || part === '.' || part === 'this') {
+ if (dig.length > 0) {
+ throw new Exception('Invalid path: ' + original, {loc: locInfo});
+ } else if (part === '..') {
+ depth++;
+ depthString += '../';
+ }
+ } else {
+ dig.push(part);
+ }
+ }
+
+ return new this.PathExpression(data, depth, dig, original, locInfo);
+}
+
+export function prepareMustache(sexpr, open, strip, locInfo) {
+ /*jshint -W040 */
+ // Must use charAt to support IE pre-10
+ var escapeFlag = open.charAt(3) || open.charAt(2),
+ escaped = escapeFlag !== '{' && escapeFlag !== '&';
+
+ return new this.MustacheStatement(sexpr, escaped, strip, this.locInfo(locInfo));
+}
+
export function prepareRawBlock(openRawBlock, content, close, locInfo) {
/*jshint -W040 */
if (openRawBlock.sexpr.path.original !== close) {