Move noConflict implementation to module
DRYs the code to avoid escapes like #1004 Fixes #1004
This commit is contained in:
+6
-11
@@ -1,4 +1,4 @@
|
||||
import Handlebars from './handlebars.runtime';
|
||||
import runtime from './handlebars.runtime';
|
||||
|
||||
// Compiler imports
|
||||
import AST from './handlebars/compiler/ast';
|
||||
@@ -7,7 +7,9 @@ import { Compiler, compile, precompile } from './handlebars/compiler/compiler';
|
||||
import JavaScriptCompiler from './handlebars/compiler/javascript-compiler';
|
||||
import Visitor from './handlebars/compiler/visitor';
|
||||
|
||||
let _create = Handlebars.create;
|
||||
import noConflict from './handlebars/no-conflict';
|
||||
|
||||
let _create = runtime.create;
|
||||
function create() {
|
||||
let hb = _create();
|
||||
|
||||
@@ -30,16 +32,9 @@ function create() {
|
||||
let inst = create();
|
||||
inst.create = create;
|
||||
|
||||
inst.Visitor = Visitor;
|
||||
noConflict(inst);
|
||||
|
||||
/* istanbul ignore next */
|
||||
let $Handlebars = global.Handlebars;
|
||||
/* istanbul ignore next */
|
||||
inst.noConflict = function() {
|
||||
if (global.Handlebars === inst) {
|
||||
global.Handlebars = $Handlebars;
|
||||
}
|
||||
};
|
||||
inst.Visitor = Visitor;
|
||||
|
||||
inst['default'] = inst;
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/*global window */
|
||||
import * as base from './handlebars/base';
|
||||
|
||||
// Each of these augment the Handlebars object. No need to setup here.
|
||||
@@ -8,6 +7,8 @@ import Exception from './handlebars/exception';
|
||||
import * as Utils from './handlebars/utils';
|
||||
import * as runtime 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() {
|
||||
let hb = new base.HandlebarsEnvironment();
|
||||
@@ -26,19 +27,11 @@ function create() {
|
||||
return hb;
|
||||
}
|
||||
|
||||
let Handlebars = create();
|
||||
Handlebars.create = create;
|
||||
let inst = create();
|
||||
inst.create = create;
|
||||
|
||||
/* istanbul ignore next */
|
||||
let root = typeof global !== 'undefined' ? global : window,
|
||||
$Handlebars = root.Handlebars;
|
||||
/* istanbul ignore next */
|
||||
Handlebars.noConflict = function() {
|
||||
if (root.Handlebars === Handlebars) {
|
||||
root.Handlebars = $Handlebars;
|
||||
}
|
||||
};
|
||||
noConflict(inst);
|
||||
|
||||
Handlebars['default'] = Handlebars;
|
||||
inst['default'] = inst;
|
||||
|
||||
export default Handlebars;
|
||||
export default inst;
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/*global window */
|
||||
export default function(Handlebars) {
|
||||
/* istanbul ignore next */
|
||||
let root = typeof global !== 'undefined' ? global : window,
|
||||
$Handlebars = root.Handlebars;
|
||||
/* istanbul ignore next */
|
||||
Handlebars.noConflict = function() {
|
||||
if (root.Handlebars === Handlebars) {
|
||||
root.Handlebars = $Handlebars;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user