diff --git a/lib/handlebars.js b/lib/handlebars.js index 69bcb410..7d7f4d45 100644 --- a/lib/handlebars.js +++ b/lib/handlebars.js @@ -9,10 +9,9 @@ import Visitor from './handlebars/compiler/visitor'; import noConflict from './handlebars/no-conflict'; -let _create = runtime.create; function create() { - let hb = _create(); - + let hb = runtime.create(); + hb.create = create; hb.compile = function(input, options) { return compile(input, options, hb); }; @@ -31,8 +30,6 @@ function create() { } let inst = create(); -inst.create = create; - noConflict(inst); inst.Visitor = Visitor; diff --git a/lib/handlebars.runtime.js b/lib/handlebars.runtime.js index 2df802dd..43569691 100644 --- a/lib/handlebars.runtime.js +++ b/lib/handlebars.runtime.js @@ -4,21 +4,43 @@ import * as base from './handlebars/base'; // (This is done to easily share code between commonjs and browse envs) import SafeString from './handlebars/safe-string'; import Exception from './handlebars/exception'; -import * as Utils from './handlebars/utils'; +import { + extend, + toString, + isFunction, + isArray, + indexOf, + escapeExpression, + isEmpty, + createFrame, + blockParams, + appendContextPath +} from './handlebars/utils'; import {checkRevision, template, wrapProgram, resolvePartial, invokePartial, noop} from './handlebars/runtime'; import noConflict from './handlebars/no-conflict'; // For compatibility and usage outside of module systems, make the Handlebars object a namespace -function create() { +export function create() { let hb = new base.HandlebarsEnvironment(); - Utils.extend(hb, base); + extend(hb, base); hb.SafeString = SafeString; hb.Exception = Exception; - hb.Utils = Utils; - hb.escapeExpression = Utils.escapeExpression; - + hb.Utils = { + extend, + toString, + isFunction, + isArray, + indexOf, + escapeExpression, + isEmpty, + createFrame, + blockParams, + appendContextPath + }; + hb.escapeExpression = escapeExpression; + hb.create = create; hb.VM = {checkRevision, template, wrapProgram, resolvePartial, invokePartial, noop}; hb.template = function(spec) { return template(spec, hb); @@ -28,7 +50,6 @@ function create() { } let inst = create(); -inst.create = create; noConflict(inst); diff --git a/lib/handlebars/utils.js b/lib/handlebars/utils.js index fa52ae50..ffa0b4f7 100644 --- a/lib/handlebars/utils.js +++ b/lib/handlebars/utils.js @@ -67,6 +67,7 @@ export function indexOf(array, value) { } + export function escapeExpression(string) { if (typeof string !== 'string') { // don't escape SafeStrings, since they're already safe @@ -88,6 +89,7 @@ export function escapeExpression(string) { return string.replace(badChars, escapeChar); } + export function isEmpty(value) { if (!value && value !== 0) { return true;