summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2014-07-13 07:24:52 -0500
committerkpdecker <kpdecker@gmail.com>2014-08-12 14:41:58 -0500
commit60701790099d3c4b30c32d498b05c46fa323df30 (patch)
tree0edb2f46fbd9aa0016b3d6b61721a9db7ce92974
parent4a4dcf16578f28bff42d755da5ece94188f75ba5 (diff)
downloadhandlebars.js-60701790099d3c4b30c32d498b05c46fa323df30.zip
handlebars.js-60701790099d3c4b30c32d498b05c46fa323df30.tar.gz
handlebars.js-60701790099d3c4b30c32d498b05c46fa323df30.tar.bz2
Track root status in ProgramNode constructor
-rw-r--r--lib/handlebars/compiler/ast.js12
-rw-r--r--spec/ast.js8
-rw-r--r--spec/parser.js2
-rw-r--r--spec/regressions.js2
-rw-r--r--src/handlebars.yy16
5 files changed, 20 insertions, 20 deletions
diff --git a/lib/handlebars/compiler/ast.js b/lib/handlebars/compiler/ast.js
index e388e54..74f276e 100644
--- a/lib/handlebars/compiler/ast.js
+++ b/lib/handlebars/compiler/ast.js
@@ -9,12 +9,12 @@ function LocationInfo(locInfo){
}
var AST = {
- ProgramNode: function(statements, inverseStrip, inverse, locInfo) {
+ ProgramNode: function(isRoot, statements, inverseStrip, inverse, locInfo) {
var inverseLocationInfo, firstInverseNode;
- if (arguments.length === 3) {
+ if (arguments.length === 4) {
locInfo = inverse;
inverse = null;
- } else if (arguments.length === 2) {
+ } else if (arguments.length === 3) {
locInfo = inverseStrip;
inverseStrip = null;
}
@@ -33,9 +33,9 @@ var AST = {
last_column: firstInverseNode.lastColumn,
first_column: firstInverseNode.firstColumn
};
- this.inverse = new AST.ProgramNode(inverse, inverseStrip, inverseLocationInfo);
+ this.inverse = new AST.ProgramNode(isRoot, inverse, inverseStrip, inverseLocationInfo);
} else {
- this.inverse = new AST.ProgramNode(inverse, inverseStrip);
+ this.inverse = new AST.ProgramNode(isRoot, inverse, inverseStrip);
}
this.strip.right = inverseStrip.left;
} else if (inverseStrip) {
@@ -142,7 +142,7 @@ var AST = {
this.type = 'block';
this.mustache = mustache;
- this.program = new AST.ProgramNode([content], locInfo);
+ this.program = new AST.ProgramNode(false, [content], locInfo);
},
ContentNode: function(string, locInfo) {
diff --git a/spec/ast.js b/spec/ast.js
index c05e45c..cad4b30 100644
--- a/spec/ast.js
+++ b/spec/ast.js
@@ -86,7 +86,7 @@ describe('ast', function() {
var sexprNode = new handlebarsEnv.AST.SexprNode([{ original: 'foo'}], null);
var mustacheNode = new handlebarsEnv.AST.MustacheNode(sexprNode, null, '{{', {});
var block = new handlebarsEnv.AST.BlockNode(mustacheNode,
- {strip: {}}, {strip: {}},
+ {statements: [], strip: {}}, {statements: [], strip: {}},
{
strip: {},
path: {original: 'foo'}
@@ -201,12 +201,12 @@ describe('ast', function() {
describe("storing location info", function(){
it("stores when `inverse` argument isn't passed", function(){
- var pn = new handlebarsEnv.AST.ProgramNode([], LOCATION_INFO);
+ var pn = new handlebarsEnv.AST.ProgramNode(false, [], LOCATION_INFO);
testLocationInfoStorage(pn);
});
it("stores when `inverse` or `stripInverse` arguments passed", function(){
- var pn = new handlebarsEnv.AST.ProgramNode([], {strip: {}}, undefined, LOCATION_INFO);
+ var pn = new handlebarsEnv.AST.ProgramNode(false, [], {strip: {}}, undefined, LOCATION_INFO);
testLocationInfoStorage(pn);
var clone = {
@@ -216,7 +216,7 @@ describe('ast', function() {
firstColumn: 0,
lastColumn: 0
};
- pn = new handlebarsEnv.AST.ProgramNode([], {strip: {}}, [ clone ], LOCATION_INFO);
+ pn = new handlebarsEnv.AST.ProgramNode(false, [], {strip: {}}, [ clone ], LOCATION_INFO);
testLocationInfoStorage(pn);
// Assert that the newly created ProgramNode has the same location
diff --git a/spec/parser.js b/spec/parser.js
index ebde171..ff12cc4 100644
--- a/spec/parser.js
+++ b/spec/parser.js
@@ -184,7 +184,7 @@ describe('parser', function() {
describe('externally compiled AST', function() {
it('can pass through an already-compiled AST', function() {
- equals(ast_for(new Handlebars.AST.ProgramNode([ new Handlebars.AST.ContentNode("Hello")])), "CONTENT[ \'Hello\' ]\n");
+ equals(ast_for(new Handlebars.AST.ProgramNode(false, [ new Handlebars.AST.ContentNode("Hello")])), "CONTENT[ \'Hello\' ]\n");
});
});
});
diff --git a/spec/regressions.js b/spec/regressions.js
index c633a21..6a7990c 100644
--- a/spec/regressions.js
+++ b/spec/regressions.js
@@ -128,7 +128,7 @@ describe('Regressions', function() {
if (Handlebars.AST) {
it("can pass through an already-compiled AST via compile/precompile", function() {
- equal(Handlebars.compile(new Handlebars.AST.ProgramNode([ new Handlebars.AST.ContentNode("Hello")]))(), 'Hello');
+ equal(Handlebars.compile(new Handlebars.AST.ProgramNode(true, [ new Handlebars.AST.ContentNode("Hello")]))(), 'Hello');
});
it("can pass through an empty string", function() {
diff --git a/src/handlebars.yy b/src/handlebars.yy
index 51796ec..fa69f73 100644
--- a/src/handlebars.yy
+++ b/src/handlebars.yy
@@ -16,17 +16,17 @@ function stripFlags(open, close) {
%%
root
- : statements EOF { return new yy.ProgramNode($1, @$); }
- | EOF { return new yy.ProgramNode([], @$); }
+ : statements EOF { return new yy.ProgramNode(true, $1, @$); }
+ | EOF { return new yy.ProgramNode(true, [], @$); }
;
program
- : simpleInverse statements -> new yy.ProgramNode([], $1, $2, @$)
- | statements simpleInverse statements -> new yy.ProgramNode($1, $2, $3, @$)
- | statements simpleInverse -> new yy.ProgramNode($1, $2, [], @$)
- | statements -> new yy.ProgramNode($1, @$)
- | simpleInverse -> new yy.ProgramNode([], @$)
- | "" -> new yy.ProgramNode([], @$)
+ : simpleInverse statements -> new yy.ProgramNode(false, [], $1, $2, @$)
+ | statements simpleInverse statements -> new yy.ProgramNode(false, $1, $2, $3, @$)
+ | statements simpleInverse -> new yy.ProgramNode(false, $1, $2, [], @$)
+ | statements -> new yy.ProgramNode(false, $1, @$)
+ | simpleInverse -> new yy.ProgramNode(false, [], @$)
+ | "" -> new yy.ProgramNode(false, [], @$)
;
statements