summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/ast.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/handlebars/compiler/ast.js')
-rw-r--r--lib/handlebars/compiler/ast.js69
1 files changed, 30 insertions, 39 deletions
diff --git a/lib/handlebars/compiler/ast.js b/lib/handlebars/compiler/ast.js
index 567e297..336492d 100644
--- a/lib/handlebars/compiler/ast.js
+++ b/lib/handlebars/compiler/ast.js
@@ -1,15 +1,12 @@
-exports.attach = function(Handlebars) {
+import Exception from "../exception";
-// BEGIN(BROWSER)
-Handlebars.AST = {};
-
-Handlebars.AST.ProgramNode = function(statements, inverse) {
+export function ProgramNode(statements, inverse) {
this.type = "program";
this.statements = statements;
- if(inverse) { this.inverse = new Handlebars.AST.ProgramNode(inverse); }
-};
+ if(inverse) { this.inverse = new ProgramNode(inverse); }
+}
-Handlebars.AST.MustacheNode = function(rawParams, hash, unescaped) {
+export function MustacheNode(rawParams, hash, unescaped) {
this.type = "mustache";
this.escaped = !unescaped;
this.hash = hash;
@@ -29,17 +26,17 @@ Handlebars.AST.MustacheNode = function(rawParams, hash, unescaped) {
// if a mustache is an eligible helper but not a definite
// helper, it is ambiguous, and will be resolved in a later
// pass or at runtime.
-};
+}
-Handlebars.AST.PartialNode = function(partialName, context) {
+export function PartialNode(partialName, context) {
this.type = "partial";
this.partialName = partialName;
this.context = context;
-};
+}
-Handlebars.AST.BlockNode = function(mustache, program, inverse, close) {
+export function BlockNode(mustache, program, inverse, close) {
if(mustache.id.original !== close.original) {
- throw new Handlebars.Exception(mustache.id.original + " doesn't match " + close.original);
+ throw new Exception(mustache.id.original + " doesn't match " + close.original);
}
this.type = "block";
@@ -50,19 +47,19 @@ Handlebars.AST.BlockNode = function(mustache, program, inverse, close) {
if (this.inverse && !this.program) {
this.isInverse = true;
}
-};
+}
-Handlebars.AST.ContentNode = function(string) {
+export function ContentNode(string) {
this.type = "content";
this.string = string;
-};
+}
-Handlebars.AST.HashNode = function(pairs) {
+export function HashNode(pairs) {
this.type = "hash";
this.pairs = pairs;
-};
+}
-Handlebars.AST.IdNode = function(parts) {
+export function IdNode(parts) {
this.type = "ID";
var original = "",
@@ -74,7 +71,7 @@ Handlebars.AST.IdNode = function(parts) {
original += (parts[i].separator || '') + part;
if (part === ".." || part === "." || part === "this") {
- if (dig.length > 0) { throw new Handlebars.Exception("Invalid path: " + original); }
+ if (dig.length > 0) { throw new Exception("Invalid path: " + original); }
else if (part === "..") { depth++; }
else { this.isScoped = true; }
}
@@ -91,45 +88,39 @@ Handlebars.AST.IdNode = function(parts) {
this.isSimple = parts.length === 1 && !this.isScoped && depth === 0;
this.stringModeValue = this.string;
-};
+}
-Handlebars.AST.PartialNameNode = function(name) {
+export function PartialNameNode(name) {
this.type = "PARTIAL_NAME";
this.name = name.original;
-};
+}
-Handlebars.AST.DataNode = function(id) {
+export function DataNode(id) {
this.type = "DATA";
this.id = id;
-};
+}
-Handlebars.AST.StringNode = function(string) {
+export function StringNode(string) {
this.type = "STRING";
this.original =
this.string =
this.stringModeValue = string;
-};
+}
-Handlebars.AST.IntegerNode = function(integer) {
+export function IntegerNode(integer) {
this.type = "INTEGER";
this.original =
this.integer = integer;
this.stringModeValue = Number(integer);
-};
+}
-Handlebars.AST.BooleanNode = function(bool) {
+export function BooleanNode(bool) {
this.type = "BOOLEAN";
this.bool = bool;
this.stringModeValue = bool === "true";
-};
+}
-Handlebars.AST.CommentNode = function(comment) {
+export function CommentNode(comment) {
this.type = "comment";
this.comment = comment;
-};
-
-// END(BROWSER)
-
-return Handlebars;
-};
-
+}