diff options
author | Yehuda Katz <wycats@gmail.com> | 2013-07-01 13:59:58 -0700 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2013-07-01 13:59:58 -0700 |
commit | 88ee4757e77f97afb206132eddb64e688700eb37 (patch) | |
tree | 08f7db62a3151dfbd44bfd6f1ec4ec6737a2bdb6 /lib/handlebars/compiler/compiler.js | |
parent | 8e2416dabb2056c07357a55b9259322f0d794ada (diff) | |
download | handlebars.js-88ee4757e77f97afb206132eddb64e688700eb37.zip handlebars.js-88ee4757e77f97afb206132eddb64e688700eb37.tar.gz handlebars.js-88ee4757e77f97afb206132eddb64e688700eb37.tar.bz2 |
Initial work on ES6 modules
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r-- | lib/handlebars/compiler/compiler.js | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 98e12b1..a21ccc0 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -1,13 +1,11 @@ -var compilerbase = require("./base"); - -exports.attach = function(Handlebars) { - -compilerbase.attach(Handlebars); - -// BEGIN(BROWSER) +import { Exception } from "handlebars/utils"; +import parse from "handlebars/compiler/base"; +import { template } from "handlebars/runtime"; /*jshint eqnull:true*/ -var Compiler = Handlebars.Compiler = function() {}; + +var Compiler = function() {}; +export default Compiler; // the foundHelper register will disambiguate helper lookup from finding a // function in a context. This is necessary for mustache compatibility, which @@ -40,6 +38,7 @@ Compiler.prototype = { return out.join("\n"); }, + equals: function(other) { var len = this.opcodes.length; if (other.opcodes.length !== len) { @@ -301,7 +300,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,35 +414,39 @@ Compiler.prototype = { } }; -Handlebars.precompile = function(input, options) { +export function precompile(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); + 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) { +export function 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); + 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); + 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); } // Template is only compiled on first use and cached after that point. @@ -454,10 +457,3 @@ Handlebars.compile = function(input, options) { return compiled.call(this, context, options); }; }; - - -// END(BROWSER) - -return Handlebars; - -}; |