1
- import { Loader , ModuleNamespace } from './loader-polyfill.js' ;
1
+ import { Loader , ModuleNamespace , REGISTRY } from './loader-polyfill.js' ;
2
2
import { resolveIfNotPlain } from './resolve.js' ;
3
3
import { addToError , global , createSymbol , baseURI } from './common.js' ;
4
4
@@ -116,18 +116,23 @@ function createLoadRecord (state, key, registration) {
116
116
RegisterLoader . prototype [ Loader . resolveInstantiate ] = function ( key , parentKey ) {
117
117
var loader = this ;
118
118
var state = this [ REGISTER_INTERNAL ] ;
119
- var registry = loader . registry [ loader . registry . _registry ] ;
119
+ var registry = this . registry [ REGISTRY ] ;
120
120
121
121
return resolveInstantiate ( loader , key , parentKey , registry , state )
122
122
. then ( function ( instantiated ) {
123
123
if ( instantiated instanceof ModuleNamespace )
124
124
return instantiated ;
125
125
126
- // if already beaten to linked, return
127
- if ( instantiated . module )
128
- return instantiated . module ;
129
-
130
126
// resolveInstantiate always returns a load record with a link record and no module value
127
+ let link = instantiated . linkRecord ;
128
+
129
+ // if already beaten to done, return
130
+ if ( ! link ) {
131
+ if ( instantiated . module )
132
+ return instantiated . module ;
133
+ throw instantiated . evalError ;
134
+ }
135
+
131
136
if ( instantiated . linkRecord . linked )
132
137
return ensureEvaluate ( loader , instantiated , instantiated . linkRecord , registry , state , undefined ) ;
133
138
@@ -148,8 +153,11 @@ function resolveInstantiate (loader, key, parentKey, registry, state) {
148
153
var load = state . records [ key ] ;
149
154
150
155
// already linked but not in main registry is ignored
151
- if ( load && ! load . module )
156
+ if ( load && ! load . module ) {
157
+ if ( load . loadError )
158
+ return Promise . reject ( load . loadError ) ;
152
159
return instantiate ( loader , load , load . linkRecord , registry , state ) ;
160
+ }
153
161
154
162
return loader . resolve ( key , parentKey )
155
163
. then ( function ( resolvedKey ) {
@@ -167,6 +175,9 @@ function resolveInstantiate (loader, key, parentKey, registry, state) {
167
175
if ( ! load || load . module )
168
176
load = createLoadRecord ( state , resolvedKey , load && load . registration ) ;
169
177
178
+ if ( load . loadError )
179
+ return Promise . reject ( load . loadError ) ;
180
+
170
181
var link = load . linkRecord ;
171
182
if ( ! link )
172
183
return load ;
@@ -286,6 +297,9 @@ function resolveInstantiateDep (loader, key, parentKey, registry, state, traceDe
286
297
if ( module && ( ! load || load . module && module !== load . module ) )
287
298
return module ;
288
299
300
+ if ( load && load . loadError )
301
+ throw load . loadError ;
302
+
289
303
// already has a module value but not already in the registry (load.module)
290
304
// means it was removed by registry.delete, so we should
291
305
// disgard the current load record creating a new one over it
@@ -401,9 +415,6 @@ function instantiateDeps (loader, load, link, registry, state, seen) {
401
415
var depLoad = link . dependencyInstantiations [ i ] ;
402
416
var depLink = depLoad . linkRecord ;
403
417
404
- if ( depLoad . loadError )
405
- throw depLoad . loadError ;
406
-
407
418
if ( ! depLink || depLink . linked )
408
419
continue ;
409
420
0 commit comments