diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-04-20 03:09:25 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-04-24 16:14:29 +0200 |
commit | 82f2b76e25a4a67e01ec67e5ebe39d14ad771ea8 (patch) | |
tree | 965f6eb89b84d65a62b49008fd972c004832ccd1 /thirdparty/systemjs/lib/global-helpers.js | |
parent | e6e0cbc387c2a77b48e4065c229daa65bf1aa0fa (diff) |
Reorganize module loading.
We now use webpack instead of SystemJS, effectively bundling modules
into one file (plus commons chunks) for every entry point. This results
in a much smaller extension size (almost half). Furthermore we use
yarn/npm even for extension run-time dependencies. This relieves us
from manually vendoring and building dependencies. It's also easier to
understand for new developers familiar with node.
Diffstat (limited to 'thirdparty/systemjs/lib/global-helpers.js')
-rw-r--r-- | thirdparty/systemjs/lib/global-helpers.js | 147 |
1 files changed, 0 insertions, 147 deletions
diff --git a/thirdparty/systemjs/lib/global-helpers.js b/thirdparty/systemjs/lib/global-helpers.js deleted file mode 100644 index 2e87f0882..000000000 --- a/thirdparty/systemjs/lib/global-helpers.js +++ /dev/null @@ -1,147 +0,0 @@ - - -function getGlobalValue(exports) { - if (typeof exports == 'string') - return readMemberExpression(exports, __global); - - if (!(exports instanceof Array)) - throw new Error('Global exports must be a string or array.'); - - var globalValue = {}; - var first = true; - for (var i = 0; i < exports.length; i++) { - var val = readMemberExpression(exports[i], __global); - if (first) { - globalValue['default'] = val; - first = false; - } - globalValue[exports[i].split('.').pop()] = val; - } - return globalValue; -} - -hook('reduceRegister_', function(reduceRegister) { - return function(load, register) { - if (register || (!load.metadata.exports && !(isWorker && load.metadata.format == 'global'))) - return reduceRegister.call(this, load, register); - - load.metadata.format = 'global'; - var entry = load.metadata.entry = createEntry(); - entry.deps = load.metadata.deps; - var globalValue = getGlobalValue(load.metadata.exports); - entry.execute = function() { - return globalValue; - }; - }; -}); - -hookConstructor(function(constructor) { - return function() { - var loader = this; - constructor.call(loader); - - var hasOwnProperty = Object.prototype.hasOwnProperty; - - // bare minimum ignores - var ignoredGlobalProps = ['_g', 'sessionStorage', 'localStorage', 'clipboardData', 'frames', 'frameElement', 'external', - 'mozAnimationStartTime', 'webkitStorageInfo', 'webkitIndexedDB', 'mozInnerScreenY', 'mozInnerScreenX']; - - var globalSnapshot; - - function forEachGlobal(callback) { - if (Object.keys) - Object.keys(__global).forEach(callback); - else - for (var g in __global) { - if (!hasOwnProperty.call(__global, g)) - continue; - callback(g); - } - } - - function forEachGlobalValue(callback) { - forEachGlobal(function(globalName) { - if (indexOf.call(ignoredGlobalProps, globalName) != -1) - return; - try { - var value = __global[globalName]; - } - catch (e) { - ignoredGlobalProps.push(globalName); - } - callback(globalName, value); - }); - } - - loader.set('@@global-helpers', loader.newModule({ - prepareGlobal: function(moduleName, exports, globals, encapsulate) { - // disable module detection - var curDefine = __global.define; - - __global.define = undefined; - - // set globals - var oldGlobals; - if (globals) { - oldGlobals = {}; - for (var g in globals) { - oldGlobals[g] = __global[g]; - __global[g] = globals[g]; - } - } - - // store a complete copy of the global object in order to detect changes - if (!exports) { - globalSnapshot = {}; - - forEachGlobalValue(function(name, value) { - globalSnapshot[name] = value; - }); - } - - // return function to retrieve global - return function() { - var globalValue = exports ? getGlobalValue(exports) : {}; - - var singleGlobal; - var multipleExports = !!exports; - - if (!exports || encapsulate) - forEachGlobalValue(function(name, value) { - if (globalSnapshot[name] === value) - return; - if (typeof value == 'undefined') - return; - - // allow global encapsulation where globals are removed - if (encapsulate) - __global[name] = undefined; - - if (!exports) { - globalValue[name] = value; - - if (typeof singleGlobal != 'undefined') { - if (!multipleExports && singleGlobal !== value) - multipleExports = true; - } - else { - singleGlobal = value; - } - } - }); - - globalValue = multipleExports ? globalValue : singleGlobal; - - // revert globals - if (oldGlobals) { - for (var g in oldGlobals) - __global[g] = oldGlobals[g]; - } - __global.define = curDefine; - - return globalValue; - }; - } - })); - }; -}); |