summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/compiler.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r--lib/handlebars/compiler/compiler.js55
1 files changed, 26 insertions, 29 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js
index 98e12b1..6656a3f 100644
--- a/lib/handlebars/compiler/compiler.js
+++ b/lib/handlebars/compiler/compiler.js
@@ -1,13 +1,12 @@
-var compilerbase = require("./base");
-
-exports.attach = function(Handlebars) {
-
-compilerbase.attach(Handlebars);
-
-// BEGIN(BROWSER)
+import { Exception } from "../utils";
+import { template } from "../runtime";
+import { parse } from "./base";
+import { JavaScriptCompiler } from "./javascript-compiler";
+import AST from "./ast";
/*jshint eqnull:true*/
-var Compiler = Handlebars.Compiler = function() {};
+
+export function Compiler() {};
// the foundHelper register will disambiguate helper lookup from finding a
// function in a context. This is necessary for mustache compatibility, which
@@ -40,6 +39,7 @@ Compiler.prototype = {
return out.join("\n");
},
+
equals: function(other) {
var len = this.opcodes.length;
if (other.opcodes.length !== len) {
@@ -301,7 +301,7 @@ Compiler.prototype = {
DATA: function(data) {
this.options.data = true;
if (data.id.isScoped || data.id.depth) {
- throw new Handlebars.Exception('Scoped data references are not supported: ' + data.original);
+ throw new Exception('Scoped data references are not supported: ' + data.original);
}
this.opcode('lookupData');
@@ -415,49 +415,46 @@ Compiler.prototype = {
}
};
-Handlebars.precompile = function(input, options) {
- if (input == null || (typeof input !== 'string' && input.constructor !== Handlebars.AST.ProgramNode)) {
- throw new Handlebars.Exception("You must pass a string or Handlebars AST to Handlebars.precompile. You passed " + input);
+export function precompile(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.precompile. You passed " + input);
}
options = options || {};
if (!('data' in options)) {
options.data = true;
}
- var ast = Handlebars.parse(input);
+
+ var ast = parse(input);
var environment = new Compiler().compile(ast, options);
- return new Handlebars.JavaScriptCompiler().compile(environment, options);
+ return new JavaScriptCompiler().compile(environment, options);
};
-Handlebars.compile = function(input, options) {
- if (input == null || (typeof input !== 'string' && input.constructor !== Handlebars.AST.ProgramNode)) {
- throw new Handlebars.Exception("You must pass a string or Handlebars AST to Handlebars.compile. You passed " + input);
+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);
}
options = options || {};
+
if (!('data' in options)) {
options.data = true;
}
+
var compiled;
- function compile() {
- var ast = Handlebars.parse(input);
+
+ function compileInput() {
+ var ast = parse(input);
var environment = new Compiler().compile(ast, options);
- var templateSpec = new Handlebars.JavaScriptCompiler().compile(environment, options, undefined, true);
- return Handlebars.template(templateSpec);
+ var templateSpec = new JavaScriptCompiler().compile(environment, options, undefined, true);
+ return template(templateSpec, options.env || Handlebars, compile);
}
// Template is only compiled on first use and cached after that point.
return function(context, options) {
if (!compiled) {
- compiled = compile();
+ compiled = compileInput();
}
return compiled.call(this, context, options);
};
};
-
-
-// END(BROWSER)
-
-return Handlebars;
-
-};