some minor refactorings

This commit is contained in:
Nils Knappmeier
2019-11-30 16:37:43 +01:00
parent c5b699db00
commit 51892c296e
3 changed files with 32 additions and 12 deletions
+2 -5
View File
@@ -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;
+28 -7
View File
@@ -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);
+2
View File
@@ -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;