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

Commit 69b2589

Browse files
committed
ensure delete re-execution (#313)
1 parent 1baaca5 commit 69b2589

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

src/loader.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,10 @@ function logloads(loads) {
939939
},
940940
// 26.3.3.3
941941
'delete': function(name) {
942-
return this._loader.modules[name] ? delete this._loader.modules[name] : false;
942+
var loader = this._loader;
943+
delete loader.importPromises[name];
944+
delete loader.moduleRecords[name];
945+
return loader.modules[name] ? delete loader.modules[name] : false;
943946
},
944947
// 26.3.3.4 entries not implemented
945948
// 26.3.3.5

test/loader/module.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export var run;
2+
3+
(function(global) {
4+
run = global.run ? 'second' : 'first';
5+
6+
global.run = true;
7+
})(typeof window == 'undefined' ? global : window);

test/system.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,30 @@ describe('System', function () {
4646

4747
});
4848

49+
describe('System registry methods', function() {
50+
51+
it('should support set, get and delete', function(done) {
52+
53+
var testPath = 'test/loader/module';
54+
55+
System.import(testPath).then(function(m) {
56+
expect(m.run).to.equal('first');
57+
System.delete(testPath);
58+
return System.import(testPath);
59+
})
60+
.then(function(m) {
61+
expect(m.run).to.equal('second');
62+
System.delete('loader.module');
63+
System.set(testPath, System.newModule({ custom: 'module' }));
64+
return System.import(testPath);
65+
})
66+
.then(function(m) {
67+
expect(m.custom).to.equal('module');
68+
})
69+
.then(done, done);
70+
});
71+
});
72+
4973
describe('an ES6 script', function () {
5074

5175
it('should import an ES6 script', function (done) {

test/test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,23 @@ function runTests() {
179179
assert(System.normalize('../a/b', '../../c/d'), '../../a/b');
180180
});
181181

182+
test('Setting & deleting modules', function(assert, err) {
183+
System['import']('loader/module').then(function(m1) {
184+
System['delete']('loader/module');
185+
System['import']('loader/module').then(function(m2) {
186+
System['delete']('loader/module');
187+
System.set('loader/module', System.newModule({custom: 'module'}));
188+
System['import']('loader/module').then(function(m3) {
189+
assert(
190+
[m1.run, 'first'],
191+
[m2.run, 'second'],
192+
[m3.custom, 'module']
193+
);
194+
}, err);
195+
}, err);
196+
}, err);
197+
});
198+
182199
test('Import a script', function(assert, err) {
183200
System['import']('syntax/script').then(function(m) {
184201
assert(!!m, true);

0 commit comments

Comments
 (0)