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

Commit

Permalink
ensure delete re-execution (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Mar 3, 2015
1 parent 1baaca5 commit 69b2589
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,10 @@ function logloads(loads) {
},
// 26.3.3.3
'delete': function(name) {
return this._loader.modules[name] ? delete this._loader.modules[name] : false;
var loader = this._loader;
delete loader.importPromises[name];
delete loader.moduleRecords[name];
return loader.modules[name] ? delete loader.modules[name] : false;
},
// 26.3.3.4 entries not implemented
// 26.3.3.5
Expand Down
7 changes: 7 additions & 0 deletions test/loader/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export var run;

(function(global) {
run = global.run ? 'second' : 'first';

global.run = true;
})(typeof window == 'undefined' ? global : window);
24 changes: 24 additions & 0 deletions test/system.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ describe('System', function () {

});

describe('System registry methods', function() {

it('should support set, get and delete', function(done) {

var testPath = 'test/loader/module';

System.import(testPath).then(function(m) {
expect(m.run).to.equal('first');
System.delete(testPath);
return System.import(testPath);
})
.then(function(m) {
expect(m.run).to.equal('second');
System.delete('loader.module');
System.set(testPath, System.newModule({ custom: 'module' }));
return System.import(testPath);
})
.then(function(m) {
expect(m.custom).to.equal('module');
})
.then(done, done);
});
});

describe('an ES6 script', function () {

it('should import an ES6 script', function (done) {
Expand Down
17 changes: 17 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,23 @@ function runTests() {
assert(System.normalize('../a/b', '../../c/d'), '../../a/b');
});

test('Setting & deleting modules', function(assert, err) {
System['import']('loader/module').then(function(m1) {
System['delete']('loader/module');
System['import']('loader/module').then(function(m2) {
System['delete']('loader/module');
System.set('loader/module', System.newModule({custom: 'module'}));
System['import']('loader/module').then(function(m3) {
assert(
[m1.run, 'first'],
[m2.run, 'second'],
[m3.custom, 'module']
);
}, err);
}, err);
}, err);
});

test('Import a script', function(assert, err) {
System['import']('syntax/script').then(function(m) {
assert(!!m, true);
Expand Down

0 comments on commit 69b2589

Please sign in to comment.