Move noConflict implementation to module

DRYs the code to avoid escapes like #1004

Fixes #1004
This commit is contained in:
kpdecker
2015-04-27 10:19:39 -05:00
parent 4a40fc8e2f
commit 972f521718
3 changed files with 25 additions and 25 deletions
+6 -11
View File
@@ -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;
+7 -14
View File
@@ -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;
+12
View File
@@ -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;
}
};
}