Skip to content

Commit 972f521

Browse files
committed
Move noConflict implementation to module
DRYs the code to avoid escapes like #1004 Fixes #1004
1 parent 4a40fc8 commit 972f521

3 files changed

Lines changed: 25 additions & 25 deletions

File tree

lib/handlebars.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Handlebars from './handlebars.runtime';
1+
import runtime from './handlebars.runtime';
22

33
// Compiler imports
44
import AST from './handlebars/compiler/ast';
@@ -7,7 +7,9 @@ import { Compiler, compile, precompile } from './handlebars/compiler/compiler';
77
import JavaScriptCompiler from './handlebars/compiler/javascript-compiler';
88
import Visitor from './handlebars/compiler/visitor';
99

10-
let _create = Handlebars.create;
10+
import noConflict from './handlebars/no-conflict';
11+
12+
let _create = runtime.create;
1113
function create() {
1214
let hb = _create();
1315

@@ -30,16 +32,9 @@ function create() {
3032
let inst = create();
3133
inst.create = create;
3234

33-
inst.Visitor = Visitor;
35+
noConflict(inst);
3436

35-
/* istanbul ignore next */
36-
let $Handlebars = global.Handlebars;
37-
/* istanbul ignore next */
38-
inst.noConflict = function() {
39-
if (global.Handlebars === inst) {
40-
global.Handlebars = $Handlebars;
41-
}
42-
};
37+
inst.Visitor = Visitor;
4338

4439
inst['default'] = inst;
4540

lib/handlebars.runtime.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/*global window */
21
import * as base from './handlebars/base';
32

43
// Each of these augment the Handlebars object. No need to setup here.
@@ -8,6 +7,8 @@ import Exception from './handlebars/exception';
87
import * as Utils from './handlebars/utils';
98
import * as runtime from './handlebars/runtime';
109

10+
import noConflict from './handlebars/no-conflict';
11+
1112
// For compatibility and usage outside of module systems, make the Handlebars object a namespace
1213
function create() {
1314
let hb = new base.HandlebarsEnvironment();
@@ -26,19 +27,11 @@ function create() {
2627
return hb;
2728
}
2829

29-
let Handlebars = create();
30-
Handlebars.create = create;
30+
let inst = create();
31+
inst.create = create;
3132

32-
/* istanbul ignore next */
33-
let root = typeof global !== 'undefined' ? global : window,
34-
$Handlebars = root.Handlebars;
35-
/* istanbul ignore next */
36-
Handlebars.noConflict = function() {
37-
if (root.Handlebars === Handlebars) {
38-
root.Handlebars = $Handlebars;
39-
}
40-
};
33+
noConflict(inst);
4134

42-
Handlebars['default'] = Handlebars;
35+
inst['default'] = inst;
4336

44-
export default Handlebars;
37+
export default inst;

lib/handlebars/no-conflict.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*global window */
2+
export default function(Handlebars) {
3+
/* istanbul ignore next */
4+
let root = typeof global !== 'undefined' ? global : window,
5+
$Handlebars = root.Handlebars;
6+
/* istanbul ignore next */
7+
Handlebars.noConflict = function() {
8+
if (root.Handlebars === Handlebars) {
9+
root.Handlebars = $Handlebars;
10+
}
11+
};
12+
}

0 commit comments

Comments
 (0)