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

Commit 887ac27

Browse files
committed
resolve simplification
1 parent 3fc752b commit 887ac27

File tree

3 files changed

+14
-33
lines changed

3 files changed

+14
-33
lines changed

core/loader-polyfill.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function Loader () {
4646
// 3.3.1
4747
Loader.prototype.constructor = Loader;
4848
// 3.3.2
49-
Loader.prototype.import = Loader.prototype.load = function (key, parent) {
49+
Loader.prototype.import = function (key, parent) {
5050
if (typeof key !== 'string')
5151
throw new TypeError('Loader import method must be passed a module key string');
5252
// custom resolveInstantiate combined hook for better perf
@@ -74,26 +74,28 @@ var RESOLVE_INSTANTIATE = Loader.resolveInstantiate = createSymbol('resolveInsta
7474
// this provides compatibility for the resolveInstantiate optimization
7575
Loader.prototype[RESOLVE_INSTANTIATE] = function (key, parent) {
7676
var loader = this;
77-
return this.resolve(key, parent)
77+
return loader.resolve(key, parent)
7878
.then(function (resolved) {
7979
var module = loader.registry.get(resolved);
8080
if (!module)
81-
throw new Error('Resolve did not define the "' + resolved + '" module into the registry.');
81+
throw new Error('Module ' + resolved + ' did not instantiate.');
8282
return module;
8383
});
8484
};
8585

86+
function ensureResolution (resolvedKey) {
87+
if (resolvedKey === undefined)
88+
throw new RangeError('No resolution found.');
89+
return resolvedKey;
90+
}
91+
8692
Loader.prototype.resolve = function (key, parent) {
8793
var loader = this;
8894
return Promise.resolve()
8995
.then(function() {
9096
return loader[RESOLVE](key, parent);
9197
})
92-
.then(function (resolvedKey) {
93-
if (resolvedKey === undefined)
94-
throw new RangeError('No resolution found.');
95-
return resolvedKey;
96-
})
98+
.then(ensureResolution)
9799
.catch(function (err) {
98100
throw addToError(err, 'Resolving ' + key + (parent ? ' to ' + parent : ''));
99101
});

core/register-loader.js

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,36 +34,15 @@ function RegisterLoader () {
3434
RegisterLoader.prototype = Object.create(Loader.prototype);
3535
RegisterLoader.prototype.constructor = RegisterLoader;
3636

37-
var RESOLVE = RegisterLoader.resolve = createSymbol('normalize');
3837
var INSTANTIATE = RegisterLoader.instantiate = createSymbol('instantiate');
3938

4039
// default normalize is the WhatWG style normalizer
41-
RegisterLoader.prototype[RESOLVE] = function (key, parentKey) {
40+
RegisterLoader.prototype[RegisterLoader.resolve = Loader.resolve] = function (key, parentKey) {
4241
return resolveIfNotPlain(key, parentKey || baseURI);
4342
};
4443

4544
RegisterLoader.prototype[INSTANTIATE] = function (key, processAnonRegister) {};
4645

47-
function ensureResolution (resolvedKey) {
48-
if (resolvedKey === undefined)
49-
throw new RangeError('No resolution found.');
50-
return resolvedKey;
51-
}
52-
53-
function resolve (key, parentKey) {
54-
var loader = this;
55-
return Promise.resolve()
56-
.then(function () {
57-
return loader[RESOLVE](key, parentKey);
58-
})
59-
.then(ensureResolution)
60-
.catch(function (err) {
61-
throw addToError(err, 'Resolving "' + key + '"' + (parentKey ? ' to ' + parentKey : ''));
62-
});
63-
}
64-
65-
RegisterLoader.prototype[Loader.resolve] = resolve;
66-
6746
// once evaluated, the linkRecord is set to undefined leaving just the other load record properties
6847
// this allows tracking new binding listeners for es modules through importerSetters
6948
// for dynamic modules, the load record is removed entirely.
@@ -157,7 +136,7 @@ function resolveInstantiate (loader, key, parentKey, registry, state) {
157136
if (load && !load.module)
158137
return instantiate(loader, load, load.linkRecord, registry, state);
159138

160-
return resolve.call(loader, key, parentKey)
139+
return loader.resolve(key, parentKey)
161140
.then(function (resolvedKey) {
162141
// main loader registry always takes preference
163142
module = registry[resolvedKey];
@@ -278,7 +257,7 @@ function resolveInstantiateDep (loader, key, parentKey, registry, state, traceDe
278257
traceDepMap[key] = key;
279258
return instantiate(loader, load, load.linkRecord, registry, state);
280259
} */
281-
return resolve.call(loader, key, parentKey)
260+
return loader.resolve(key, parentKey)
282261
.then(function (resolvedKey) {
283262
if (traceDepMap)
284263
traceDepMap[key] = key;

test/3-register-loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 "plain-name"\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 () {

0 commit comments

Comments
 (0)