named register to define into plain

This commit is contained in:
Guy Bedford 2018-11-01 12:55:07 +02:00
parent 47f7429ea2
commit bc63fbb04d
2 changed files with 12 additions and 4 deletions

View File

@ -2,8 +2,8 @@
* SystemJS named register extension
* Supports System.register('name', [..deps..], function (_export, _context) { ... })
*
* Names are resolved origin-relative, so
* System.register(['x']) must be imported as System.import('/x')
* Names are written to the registry as-is
* System.register('x', ...) can be imported as System.import('x')
*/
(function () {
const systemJSPrototype = System.constructor.prototype;
@ -15,7 +15,15 @@
if (typeof name !== 'string')
return register.apply(this, arguments);
registerRegistry['bundle:' + name] = [deps, declare];
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;

View File

@ -2,7 +2,7 @@ suite('Named System.register', function() {
test('Loading a named System.register bundle', function () {
return System.import('./fixtures/browser/named-bundle.js').then(function (m) {
assert.equal(Object.keys(m).length, 0);
return System.import('bundle:a');
return System.import('a');
})
.then(function (m) {
assert.equal(m.a, 'b');