Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

Commit 3dfe9a6

Browse files
committed
remove base key as standard constructor
1 parent 90b318d commit 3dfe9a6

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

core/loader-polyfill.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { baseURI, addToError, createSymbol } from './common.js';
1+
import { addToError, createSymbol } from './common.js';
22

33
export { Loader, Module, Module as ModuleNamespace }
44

@@ -40,8 +40,7 @@ function arrayValues (arr) {
4040
* We skip the entire native internal pipeline, just providing the bare API
4141
*/
4242
// 3.1.1
43-
function Loader (baseKey) {
44-
this.key = baseKey || baseURI;
43+
function Loader () {
4544
this.registry = new Registry();
4645
}
4746
// 3.3.1
@@ -51,7 +50,7 @@ Loader.prototype.import = Loader.prototype.load = function (key, parent) {
5150
if (typeof key !== 'string')
5251
throw new TypeError('Loader import method must be passed a module key string');
5352
// custom resolveInstantiate combined hook for better perf
54-
return Promise.resolve(this[RESOLVE_INSTANTIATE](key, parent || this.key))
53+
return Promise.resolve(this[RESOLVE_INSTANTIATE](key, parent))
5554
//.then(Module.evaluate)
5655
.catch(function (err) {
5756
throw addToError(err, 'Loading ' + key + (parent ? ' from ' + parent : ''));

core/register-loader.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Loader, Module, } from './loader-polyfill.js';
22
import { resolveIfNotPlain } from './resolve.js';
3-
import { addToError, global, createSymbol } from './common.js';
3+
import { addToError, global, createSymbol, baseURI } from './common.js';
44

55
export default RegisterLoader;
66

@@ -18,8 +18,8 @@ export default RegisterLoader;
1818
var REGISTER_REGISTRY = createSymbol('registerRegistry');
1919
var REGISTERED_LAST_ANON = createSymbol('registeredLastAnon');
2020

21-
function RegisterLoader (baseKey) {
22-
Loader.apply(this, arguments);
21+
function RegisterLoader () {
22+
Loader.call(this);
2323

2424
// last anonymous System.register call
2525
this[REGISTERED_LAST_ANON] = undefined;
@@ -44,7 +44,7 @@ RegisterLoader.prototype[RESOLVE] = function (key, parentKey) {
4444
// normalization shortpath for already in registry
4545
if (this[REGISTER_REGISTRY][key] || this.registry._registry[key])
4646
return key;
47-
return resolveIfNotPlain(key, parentKey);
47+
return resolveIfNotPlain(key, parentKey || baseURI);
4848
};
4949

5050
RegisterLoader.prototype[INSTANTIATE] = function (key, processAnonRegister) {};
@@ -63,7 +63,7 @@ function resolve (key, parentKey) {
6363
})
6464
.then(ensureResolution)
6565
.catch(function (err) {
66-
throw addToError(err, 'Resolving dependency "' + key + '" to ' + parentKey);
66+
throw addToError(err, 'Resolving "' + key + '"' + (parentKey ? ' to ' + parentKey : ''));
6767
});
6868
}
6969

test/2-loader-api.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import assert from 'assert';
2-
import { Loader, Module, InternalModuleNamespace } from '../core/loader-polyfill.js';
2+
import { Loader, Module, ModuleNamespace } from '../core/loader-polyfill.js';
33
import { pathToFileUrl } from '../core/common.js';
44

55
describe('Loader Polyfill API', function() {
@@ -12,11 +12,11 @@ describe('Loader Polyfill API', function() {
1212
it('Should support the full registry API', function() {
1313
assert(loader.registry);
1414

15-
loader.registry.set('asdf', new InternalModuleNamespace({ asdf: 'asdf' }));
15+
loader.registry.set('asdf', new ModuleNamespace({ asdf: 'asdf' }));
1616
assert(loader.registry.has('asdf'));
1717
var m = loader.registry.get('asdf');
1818
assert(m);
19-
assert(m instanceof InternalModuleNamespace);
19+
assert(m instanceof ModuleNamespace);
2020
assert.equal(m.asdf, 'asdf');
2121

2222
for (var k of loader.registry.keys())

test/3-register-loader.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ describe('System Register Loader', function() {
184184

185185
describe('Errors', function () {
186186

187-
var testPath = fileUrlToPath(loader.key) + 'register-modules/';
187+
var testPath = fileUrlToPath(loader.baseKey) + 'register-modules/';
188188

189189
async function getImportError(module) {
190190
try {
@@ -198,7 +198,7 @@ describe('System Register Loader', function() {
198198

199199
it('should give a plain name error', async function () {
200200
var err = await getImportError('plain-name');
201-
assert.equal(err, 'Error: No resolution found.\n Resolving dependency "plain-name" to ' + fileUrlToPath(loader.key) + '\n Loading plain-name');
201+
assert.equal(err, 'Error: No resolution found.\n Resolving "plain-name"\n Loading plain-name');
202202
});
203203

204204
it('should throw if on syntax error', async function () {
@@ -231,7 +231,7 @@ describe('System Register Loader', function() {
231231
});
232232

233233
it('should load mixed bundles of register and registerDynamic', async function () {
234-
new Module().require(path.resolve(fileUrlToPath(loader.key), 'dynamic-modules/mixed-bundle.js'));
234+
new Module().require(path.resolve(fileUrlToPath(loader.baseKey), 'dynamic-modules/mixed-bundle.js'));
235235
var m = await loader.import('tree/first');
236236
assert.equal(m.p, 5);
237237
assert.equal(m.q, 4);

test/fixtures/system-register-loader.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { resolveIfNotPlain } from '../../core/resolve.js';
1010
* If the module does not call System.register, an error will be thrown
1111
*/
1212
function SystemRegisterLoader (baseKey) {
13-
baseKey = resolveIfNotPlain(baseKey || (isNode ? process.cwd() : '.'), baseURI) || baseKey;
14-
RegisterLoader.call(this, baseKey);
13+
this.baseKey = resolveIfNotPlain(baseKey || (isNode ? process.cwd() : '.'), baseURI) || baseKey;
14+
RegisterLoader.call(this);
1515

1616
var loader = this;
1717

@@ -37,7 +37,7 @@ SystemRegisterLoader.prototype = Object.create(RegisterLoader.prototype);
3737
// normalize is never given a relative name like "./x", that part is already handled
3838
// so we just need to do plain name detect to throw as in the WhatWG spec
3939
SystemRegisterLoader.prototype[RegisterLoader.resolve] = function (key, parent) {
40-
return RegisterLoader.prototype[RegisterLoader.resolve].call(this, key, parent);
40+
return RegisterLoader.prototype[RegisterLoader.resolve].call(this, key, parent || this.baseKey);
4141
};
4242

4343
var fs;

0 commit comments

Comments
 (0)