diff options
author | kpdecker <kpdecker@gmail.com> | 2013-07-30 11:03:12 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2013-10-14 22:50:50 -0500 |
commit | 1de6cee1b247f5dd133e1ff3141b893fb427ff94 (patch) | |
tree | 69472e49a84ed76f0e8a90fc6ce546fe8e9741e0 /lib/handlebars/compiler/ast.js | |
parent | 151e6d49c05dd93305a6ee1cad57154a01396ea0 (diff) | |
download | handlebars.js-1de6cee1b247f5dd133e1ff3141b893fb427ff94.zip handlebars.js-1de6cee1b247f5dd133e1ff3141b893fb427ff94.tar.gz handlebars.js-1de6cee1b247f5dd133e1ff3141b893fb427ff94.tar.bz2 |
Load strip flags from lex stream
Diffstat (limited to 'lib/handlebars/compiler/ast.js')
-rw-r--r-- | lib/handlebars/compiler/ast.js | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/lib/handlebars/compiler/ast.js b/lib/handlebars/compiler/ast.js index db7063c..f6229e2 100644 --- a/lib/handlebars/compiler/ast.js +++ b/lib/handlebars/compiler/ast.js @@ -1,16 +1,25 @@ import Exception from "../exception"; -export function ProgramNode(statements, inverse) { +export function ProgramNode(statements, inverseStrip, inverse) { this.type = "program"; this.statements = statements; - if(inverse) { this.inverse = new ProgramNode(inverse); } + this.strip = {}; + + if(inverse) { + this.inverse = new ProgramNode(inverse, inverseStrip); + this.strip.right = inverseStrip.left; + } else if (inverseStrip) { + this.strip.left = inverseStrip.right; + } } -export function MustacheNode(rawParams, hash, open) { +export function MustacheNode(rawParams, hash, open, strip) { this.type = "mustache"; this.hash = hash; + this.strip = strip; - this.escaped = open[2] !== '{' && open[2] !== '&'; + var escapeFlag = open[3] || open[2]; + this.escaped = escapeFlag !== '{' && escapeFlag !== '&'; var id = this.id = rawParams[0]; var params = this.params = rawParams.slice(1); @@ -29,15 +38,16 @@ export function MustacheNode(rawParams, hash, open) { // pass or at runtime. } -export function PartialNode(partialName, context) { +export function PartialNode(partialName, context, strip) { this.type = "partial"; this.partialName = partialName; this.context = context; + this.strip = strip; } export function BlockNode(mustache, program, inverse, close) { - if(mustache.id.original !== close.original) { - throw new Exception(mustache.id.original + " doesn't match " + close.original); + if(mustache.id.original !== close.path.original) { + throw new Exception(mustache.id.original + " doesn't match " + close.path.original); } this.type = "block"; @@ -45,7 +55,15 @@ export function BlockNode(mustache, program, inverse, close) { this.program = program; this.inverse = inverse; - if (this.inverse && !this.program) { + this.strip = { + left: mustache.strip.left, + right: close.strip.right + }; + + (program || inverse).strip.left = mustache.strip.right; + (inverse || program).strip.right = close.strip.left; + + if (inverse && !program) { this.isInverse = true; } } |