From 5b99ee22eac77e045bbc6405099279ea4e9d79bb Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Thu, 31 Dec 2020 13:05:28 -0700 Subject: [PATCH] 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 --- src/features/registry.js | 2 +- src/system-core.js | 15 +++++++++------ test/browser/core.js | 1 + test/fixtures/browser/link-error-child2.js | 7 +++++++ test/fixtures/browser/link-error.js | 2 +- 5 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 test/fixtures/browser/link-error-child2.js diff --git a/src/features/registry.js b/src/features/registry.js index e61eb8c6..bf3d7770 100644 --- a/src/features/registry.js +++ b/src/features/registry.js @@ -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; diff --git a/src/system-core.js b/src/system-core.js index a7ab11f2..595b5347 100644 --- a/src/system-core.js +++ b/src/system-core.js @@ -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, {}); }) diff --git a/test/browser/core.js b/test/browser/core.js index 2d2f7f7f..acd94f70 100644 --- a/test/browser/core.js +++ b/test/browser/core.js @@ -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'))); } ); }); diff --git a/test/fixtures/browser/link-error-child2.js b/test/fixtures/browser/link-error-child2.js new file mode 100644 index 00000000..a8dbf7cb --- /dev/null +++ b/test/fixtures/browser/link-error-child2.js @@ -0,0 +1,7 @@ +System.register([], function (_export) { + return { + execute: function () { + _export('default', 'link-error-child2 instantiated successfully'); + } + }; +}); \ No newline at end of file diff --git a/test/fixtures/browser/link-error.js b/test/fixtures/browser/link-error.js index 918462e6..bc8d0693 100644 --- a/test/fixtures/browser/link-error.js +++ b/test/fixtures/browser/link-error.js @@ -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 () { }