diff --git a/lib/handlebars/no-conflict.js b/lib/handlebars/no-conflict.js index f89e7aa9..91ef1da5 100644 --- a/lib/handlebars/no-conflict.js +++ b/lib/handlebars/no-conflict.js @@ -1,12 +1,22 @@ -/* global global, window */ +/* global globalThis */ export default function(Handlebars) { /* istanbul ignore next */ - let root = typeof global !== 'undefined' ? global : window, - $Handlebars = root.Handlebars; + // https://mathiasbynens.be/notes/globalthis + (function() { + if (typeof globalThis === 'object') return; + Object.prototype.__defineGetter__('__magic__', function() { + return this; + }); + __magic__.globalThis = __magic__; // eslint-disable-line no-undef + delete Object.prototype.__magic__; + })(); + + const $Handlebars = globalThis.Handlebars; + /* istanbul ignore next */ Handlebars.noConflict = function() { - if (root.Handlebars === Handlebars) { - root.Handlebars = $Handlebars; + if (globalThis.Handlebars === Handlebars) { + globalThis.Handlebars = $Handlebars; } return Handlebars; };