mirror of
https://github.com/systemjs/systemjs.git
synced 2026-01-18 14:53:14 +00:00
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:
parent
d0e76b12e0
commit
5b99ee22ea
@ -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;
|
||||
|
||||
@ -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, {});
|
||||
})
|
||||
|
||||
@ -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')));
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
7
test/fixtures/browser/link-error-child2.js
vendored
Normal file
7
test/fixtures/browser/link-error-child2.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
System.register([], function (_export) {
|
||||
return {
|
||||
execute: function () {
|
||||
_export('default', 'link-error-child2 instantiated successfully');
|
||||
}
|
||||
};
|
||||
});
|
||||
2
test/fixtures/browser/link-error.js
vendored
2
test/fixtures/browser/link-error.js
vendored
@ -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 () {
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user