summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler
diff options
context:
space:
mode:
authortomhuda <tomhuda@tilde.io>2012-05-28 19:06:26 -0700
committertomhuda <tomhuda@tilde.io>2012-05-28 19:06:26 -0700
commit0afc8b58d218d6220d5efdd2509754d13d9e1c55 (patch)
tree30c6bc9ddc743c13bbe69295f09bef9c1df5ca3a /lib/handlebars/compiler
parent1082ec2414e7d9c0cd5dcafa0dfa5510e3b1ed60 (diff)
downloadhandlebars.js-0afc8b58d218d6220d5efdd2509754d13d9e1c55.zip
handlebars.js-0afc8b58d218d6220d5efdd2509754d13d9e1c55.tar.gz
handlebars.js-0afc8b58d218d6220d5efdd2509754d13d9e1c55.tar.bz2
Clean up parser tests and AST printer
Diffstat (limited to 'lib/handlebars/compiler')
-rw-r--r--lib/handlebars/compiler/ast.js4
-rw-r--r--lib/handlebars/compiler/printer.js44
2 files changed, 19 insertions, 29 deletions
diff --git a/lib/handlebars/compiler/ast.js b/lib/handlebars/compiler/ast.js
index 8381ca5..d61377e 100644
--- a/lib/handlebars/compiler/ast.js
+++ b/lib/handlebars/compiler/ast.js
@@ -54,6 +54,10 @@ var Handlebars = require('./base');
this.mustache = mustache;
this.program = program;
this.inverse = inverse;
+
+ if (this.inverse && !this.program) {
+ this.isInverse = true;
+ }
};
Handlebars.AST.ContentNode = function(string) {
diff --git a/lib/handlebars/compiler/printer.js b/lib/handlebars/compiler/printer.js
index b7485b7..8157190 100644
--- a/lib/handlebars/compiler/printer.js
+++ b/lib/handlebars/compiler/printer.js
@@ -18,31 +18,17 @@ Handlebars.PrintVisitor.prototype.pad = function(string, newline) {
};
Handlebars.PrintVisitor.prototype.program = function(program) {
- var out = this.pad("PROGRAM:"),
+ var out = "",
statements = program.statements,
inverse = program.inverse,
i, l;
- this.padding++;
-
for(i=0, l=statements.length; i<l; i++) {
out = out + this.accept(statements[i]);
}
this.padding--;
- if(inverse) {
- out = out + this.pad("{{^}}");
-
- this.padding++;
-
- for(i=0, l=inverse.statements.length; i<l; i++) {
- out = out + this.accept(inverse.statements[i]);
- }
- }
-
- this.padding--;
-
return out;
};
@@ -52,25 +38,25 @@ Handlebars.PrintVisitor.prototype.block = function(block) {
out = out + this.pad("BLOCK:");
this.padding++;
out = out + this.accept(block.mustache);
- out = out + this.accept(block.program);
- this.padding--;
-
- return out;
-};
-
-Handlebars.PrintVisitor.prototype.inverse = function(block) {
- var out = "";
-
- out = out + this.pad("INVERSE:");
- this.padding++;
- out = out + this.accept(block.mustache);
- out = out + this.accept(block.program);
+ if (block.program) {
+ out = out + this.pad("PROGRAM:");
+ this.padding++;
+ out = out + this.accept(block.program);
+ this.padding--;
+ }
+ if (block.inverse) {
+ if (block.program) { this.padding++; }
+ out = out + this.pad("{{^}}");
+ this.padding++;
+ out = out + this.accept(block.inverse);
+ this.padding--;
+ if (block.program) { this.padding--; }
+ }
this.padding--;
return out;
};
-
Handlebars.PrintVisitor.prototype.mustache = function(mustache) {
var params = mustache.params, paramStrings = [], hash;