summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'lib/handlebars/compiler')
-rw-r--r--lib/handlebars/compiler/ast.js34
-rw-r--r--lib/handlebars/compiler/base.js6
-rw-r--r--lib/handlebars/compiler/compiler.js14
-rw-r--r--lib/handlebars/compiler/javascript-compiler.js17
-rw-r--r--lib/handlebars/compiler/printer.js2
5 files changed, 44 insertions, 29 deletions
diff --git a/lib/handlebars/compiler/ast.js b/lib/handlebars/compiler/ast.js
index fcf5c6e..b61fa0e 100644
--- a/lib/handlebars/compiler/ast.js
+++ b/lib/handlebars/compiler/ast.js
@@ -1,12 +1,14 @@
-import { Exception } from "handlebars/utils";
+import { Exception } from "../utils";
-export function ProgramNode(statements, inverse) {
+var exports = {};
+
+exports.ProgramNode = 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); }
};
-export function MustacheNode(rawParams, hash, unescaped) {
+exports.MustacheNode = function(rawParams, hash, unescaped) {
this.type = "mustache";
this.escaped = !unescaped;
this.hash = hash;
@@ -28,13 +30,13 @@ export function MustacheNode(rawParams, hash, unescaped) {
// pass or at runtime.
};
-export function PartialNode(partialName, context) {
+exports.PartialNode = function(partialName, context) {
this.type = "partial";
this.partialName = partialName;
this.context = context;
};
-export function BlockNode(mustache, program, inverse, close) {
+exports.BlockNode = function(mustache, program, inverse, close) {
if(mustache.id.original !== close.original) {
throw new Exception(mustache.id.original + " doesn't match " + close.original);
}
@@ -49,17 +51,17 @@ export function BlockNode(mustache, program, inverse, close) {
}
};
-export function ContentNode(string) {
+exports.ContentNode = function(string) {
this.type = "content";
this.string = string;
};
-export function HashNode(pairs) {
+exports.HashNode = function(pairs) {
this.type = "hash";
this.pairs = pairs;
};
-export function IdNode(part) {
+exports.IdNode = function(parts) {
this.type = "ID";
var original = "",
@@ -90,37 +92,39 @@ export function IdNode(part) {
this.stringModeValue = this.string;
};
-export function PartialNameNode(name) {
+exports.PartialNameNode = function(name) {
this.type = "PARTIAL_NAME";
this.name = name.original;
};
-export function DataNode(id) {
+exports.DataNode = function(id) {
this.type = "DATA";
this.id = id;
};
-export function StringNode(string) {
+exports.StringNode = function(string) {
this.type = "STRING";
this.original =
this.string =
this.stringModeValue = string;
};
-export function IntegerNode(integer) {
+exports.IntegerNode = function(integer) {
this.type = "INTEGER";
this.original =
this.integer = integer;
this.stringModeValue = Number(integer);
};
-export function BooleanNode(bool) {
+exports.BooleanNode = function(bool) {
this.type = "BOOLEAN";
this.bool = bool;
this.stringModeValue = bool === "true";
};
-export function CommentNode(comment) {
+exports.CommentNode = function(comment) {
this.type = "comment";
this.comment = comment;
};
+
+export default exports;
diff --git a/lib/handlebars/compiler/base.js b/lib/handlebars/compiler/base.js
index 8dd464d..adbf4f2 100644
--- a/lib/handlebars/compiler/base.js
+++ b/lib/handlebars/compiler/base.js
@@ -1,7 +1,7 @@
-import { parser } from "handlebars/compiler/parser";
-module AST from "handlebars/compiler/ast":
+import parser from "./parser";
+import AST from "./ast";
-export Parser = parser;
+export var parser = parser;
export function parse(input) {
// Just return if an already-compile AST was passed in.
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js
index 6e051b7..b779617 100644
--- a/lib/handlebars/compiler/compiler.js
+++ b/lib/handlebars/compiler/compiler.js
@@ -1,6 +1,8 @@
-import { Exception } from "handlebars/utils";
-import parse from "handlebars/compiler/base";
-import { template } from "handlebars/runtime";
+import { Exception } from "../utils";
+import { template } from "../runtime";
+import { parse } from "./base";
+import { JavaScriptCompiler } from "./javascript-compiler";
+import AST from "./ast";
/*jshint eqnull:true*/
@@ -414,7 +416,7 @@ Compiler.prototype = {
};
export function precompile(input, options) {
- if (input == null || (typeof input !== 'string' && input.constructor !== Handlebars.AST.ProgramNode)) {
+ if (input == null || (typeof input !== 'string' && input.constructor !== AST.ProgramNode)) {
throw new Exception("You must pass a string or Handlebars AST to Handlebars.precompile. You passed " + input);
}
@@ -428,8 +430,8 @@ export function precompile(input, options) {
return new JavaScriptCompiler().compile(environment, options);
};
-export function compile = function(input, options) {
- if (input == null || (typeof input !== 'string' && input.constructor !== Handlebars.AST.ProgramNode)) {
+export function compile(input, options) {
+ if (input == null || (typeof input !== 'string' && input.constructor !== AST.ProgramNode)) {
throw new Exception("You must pass a string or Handlebars AST to Handlebars.compile. You passed " + input);
}
diff --git a/lib/handlebars/compiler/javascript-compiler.js b/lib/handlebars/compiler/javascript-compiler.js
index f5d70ee..a416431 100644
--- a/lib/handlebars/compiler/javascript-compiler.js
+++ b/lib/handlebars/compiler/javascript-compiler.js
@@ -1,10 +1,9 @@
-import { COMPILER_REVISION, REVISION_CHANGES } from "handlebars/base";
+import { COMPILER_REVISION, REVISION_CHANGES } from "../base";
function Literal(value) {
this.value = value;
};
-
export function JavaScriptCompiler() {};
JavaScriptCompiler.prototype = {
@@ -44,7 +43,9 @@ JavaScriptCompiler.prototype = {
this.environment = environment;
this.options = options || {};
- Handlebars.log(Handlebars.logger.DEBUG, this.environment.disassemble() + "\n\n");
+ // TODO: a module-compatible logger
+ // Handlebars.log(Handlebars.logger.DEBUG, this.environment.disassemble() + "\n\n");
+ log(this.environment.disassemble() + "\n\n");
this.name = this.environment.name;
this.isChild = !!context;
@@ -166,7 +167,11 @@ JavaScriptCompiler.prototype = {
return Function.apply(this, params);
} else {
var functionSource = 'function ' + (this.name || '') + '(' + params.join(',') + ') {\n ' + source + '}';
- Handlebars.log(Handlebars.logger.DEBUG, functionSource + "\n\n");
+
+ // TODO: a module-compatible logger
+ //Handlebars.log(Handlebars.logger.DEBUG, functionSource + "\n\n");
+ log(functionSource + "\n\n");
+
return functionSource;
}
},
@@ -841,3 +846,7 @@ JavaScriptCompiler.isValidJavaScriptVariableName = function(name) {
}
return false;
};
+
+function log(string) {
+ //console.log(string);
+}
diff --git a/lib/handlebars/compiler/printer.js b/lib/handlebars/compiler/printer.js
index c6e08bb..0280960 100644
--- a/lib/handlebars/compiler/printer.js
+++ b/lib/handlebars/compiler/printer.js
@@ -1,4 +1,4 @@
-import Visitor from "handlebars/compiler/visitor";
+import Visitor from "./visitor";
export function print(ast) {
return new PrintVisitor().accept(ast);