summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2015-04-27 10:19:39 -0500
committerkpdecker <kpdecker@gmail.com>2015-04-27 10:19:50 -0500
commit972f52171878ce88af455d7e8fac401a27ba0168 (patch)
tree47a55984c9154fda9636cf54b84f9631a2cdaa08
parent4a40fc8e2f2d69b94188183a8324561b6e03ab6f (diff)
downloadhandlebars.js-972f52171878ce88af455d7e8fac401a27ba0168.zip
handlebars.js-972f52171878ce88af455d7e8fac401a27ba0168.tar.gz
handlebars.js-972f52171878ce88af455d7e8fac401a27ba0168.tar.bz2
Move noConflict implementation to module
DRYs the code to avoid escapes like #1004 Fixes #1004
-rw-r--r--lib/handlebars.js17
-rw-r--r--lib/handlebars.runtime.js21
-rw-r--r--lib/handlebars/no-conflict.js12
3 files changed, 25 insertions, 25 deletions
diff --git a/lib/handlebars.js b/lib/handlebars.js
index 3f3ba48..f114959 100644
--- a/lib/handlebars.js
+++ b/lib/handlebars.js
@@ -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;
diff --git a/lib/handlebars.runtime.js b/lib/handlebars.runtime.js
index 75a6a7a..3d05b54 100644
--- a/lib/handlebars.runtime.js
+++ b/lib/handlebars.runtime.js
@@ -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;
diff --git a/lib/handlebars/no-conflict.js b/lib/handlebars/no-conflict.js
new file mode 100644
index 0000000..a421f57
--- /dev/null
+++ b/lib/handlebars/no-conflict.js
@@ -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;
+ }
+ };
+}