Allow deletion of uninstantiated modules whose top level parent import finished. Resolves #2286. (#2291)

* Reproduce issue #2286.

* Making test more clear

* Fix

* Self review

* Add load.p

* possible parent fix

* optional p

* parent restriction

* Fix

* Update src/system-core.js

* another variation

Co-authored-by: Guy Bedford <guybedford@gmail.com>
This commit is contained in:
Joel Denning 2020-12-31 13:05:28 -07:00 committed by GitHub
parent d0e76b12e0
commit 5b99ee22ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 8 deletions

View File

@ -67,7 +67,7 @@ systemJSPrototype.delete = function (id) {
var load = registry[id];
// in future we can support load.E case by failing load first
// but that will require TLA callbacks to be implemented
if (!load || load.e !== null || load.E)
if (!load || (load.p && load.p.e !== null) || load.E)
return false;
var importerSetters = load.i;

View File

@ -186,8 +186,6 @@ export function getOrCreateLoad (loader, id, firstParentUrl) {
// dependency load records
d: undefined,
// execution function
// set to NULL immediately after execution (or on any failure) to indicate execution has happened
// in such a case, C should be used, and E, I, L will be emptied
e: undefined,
// On execution we have populated:
@ -199,18 +197,23 @@ export function getOrCreateLoad (loader, id, firstParentUrl) {
// On execution, L, I, E cleared
// Promise for top-level completion
C: undefined
C: undefined,
// parent instantiator / executor
p: undefined
};
}
function instantiateAll (loader, load, loaded) {
function instantiateAll (loader, load, parent, loaded) {
if (!loaded[load.id]) {
loaded[load.id] = true;
// load.L may be undefined for already-instantiated
return Promise.resolve(load.L)
.then(function () {
if (!load.p || load.p.e === null)
load.p = parent;
return Promise.all(load.d.map(function (dep) {
return instantiateAll(loader, dep, loaded);
return instantiateAll(loader, dep, parent, loaded);
}));
})
.catch(function (err) {
@ -224,7 +227,7 @@ function instantiateAll (loader, load, loaded) {
}
function topLevelLoad (loader, load) {
return load.C = instantiateAll(loader, load, {})
return load.C = instantiateAll(loader, load, load, {})
.then(function () {
return postOrderExec(loader, load, {});
})

View File

@ -313,6 +313,7 @@ suite('SystemJS Standard Tests', function() {
assert.ok(System.delete(System.resolve('fixtures/link-error.js')));
assert.ok(System.delete(System.resolve('fixtures/link-error-child.js')));
assert.ok(System.delete(System.resolve('fixtures/not-found.js')));
assert.ok(System.delete(System.resolve('fixtures/link-error-child2.js')));
}
);
});

View File

@ -0,0 +1,7 @@
System.register([], function (_export) {
return {
execute: function () {
_export('default', 'link-error-child2 instantiated successfully');
}
};
});

View File

@ -1,4 +1,4 @@
System.register(['./link-error-child.js'], function () {
System.register(['./link-error-child.js', './link-error-child2.js'], function () {
return {
execute: function () {
}