systemjs
Version:
Dynamic ES module loader
33 lines (28 loc) • 1.15 kB
JavaScript
/*
* SystemJS named register extension
* Supports System.register('name', [..deps..], function (_export, _context) { ... })
*
* Names are written to the registry as-is
* System.register('x', ...) can be imported as System.import('x')
*/
(function () {
const systemJSPrototype = System.constructor.prototype;
const registerRegistry = Object.create(null);
const register = systemJSPrototype.register;
systemJSPrototype.register = function (name, deps, declare) {
if (typeof name !== 'string')
return register.apply(this, arguments);
registerRegistry[name] = [deps, declare];
};
const resolve = systemJSPrototype.resolve;
systemJSPrototype.resolve = function (id, parentURL) {
if (id[0] === '/' || id[0] === '.' && (id[1] === '/' || id[1] === '.' && id[2] === '/'))
return resolve.call(this, id, parentURL);
if (registerRegistry[id])
return id;
};
const instantiate = systemJSPrototype.instantiate;
systemJSPrototype.instantiate = function (url, firstParentUrl) {
return registerRegistry[url] || instantiate.call(this, url, firstParentUrl);
};
})();