diff options
author | Kevin Decker <kpdecker@gmail.com> | 2013-10-12 14:22:10 -0700 |
---|---|---|
committer | Kevin Decker <kpdecker@gmail.com> | 2013-10-12 14:22:10 -0700 |
commit | 583141de7cb61eb70eaa6b33c25f475f3048071b (patch) | |
tree | 47c419f82f2941fbde5ff5aa33a85b79d6772b4c /lib/handlebars/compiler/compiler.js | |
parent | 782aae95d0b430058e2f65b8eba1621453f9055e (diff) | |
parent | 3f96319f103d1e9dc4a6de220d2a9934e00df0b6 (diff) | |
download | handlebars.js-583141de7cb61eb70eaa6b33c25f475f3048071b.zip handlebars.js-583141de7cb61eb70eaa6b33c25f475f3048071b.tar.gz handlebars.js-583141de7cb61eb70eaa6b33c25f475f3048071b.tar.bz2 |
Merge pull request #628 from wycats/es6-modules
Convert code to ES6 modules
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 58 |
1 files changed, 26 insertions, 32 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 98e12b1..50195e3 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -1,13 +1,9 @@ -var compilerbase = require("./base"); +import Exception from "../exception"; +import { parse } from "./base"; +import JavaScriptCompiler from "./javascript-compiler"; +module AST from "./ast"; -exports.attach = function(Handlebars) { - -compilerbase.attach(Handlebars); - -// BEGIN(BROWSER) - -/*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 +36,7 @@ Compiler.prototype = { return out.join("\n"); }, + equals: function(other) { var len = this.opcodes.length; if (other.opcodes.length !== len) { @@ -301,7 +298,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 +412,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, env) { + 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 env.template(templateSpec); } // 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; - -}; +} |