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

Commit 67f45bf

Browse files
committed
Merge System.define correction
1 parent 48acf7e commit 67f45bf

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

src/loader.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,12 @@ function logloads(loads) {
345345
for (var i = 0, l = loader.loads.length; i < l; i++) {
346346
if (loader.loads[i].name == name) {
347347
existingLoad = loader.loads[i];
348+
349+
if(step == 'translate' && !existingLoad.source) {
350+
existingLoad.address = stepState.moduleAddress;
351+
proceedToTranslate(loader, existingLoad, Promise.resolve(stepState.moduleSource));
352+
}
353+
348354
return existingLoad.linkSets[0].done.then(function() {
349355
resolve(existingLoad);
350356
});

test/loader/master.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import 'slave';

test/system.spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,36 @@ describe('System', function () {
375375
});
376376

377377
});
378+
379+
describe('#System.define', function () {
380+
381+
it('should load System.define', function(done) {
382+
var oldLocate = System.locate;
383+
var slaveLocatePromise = new Promise(function(resolve, reject) {
384+
385+
System.locate = function(load) {
386+
if(load.name === 'slave') {
387+
setTimeout(function() {
388+
System.define('slave', 'var double = [1,2,3].map(i => i * 2);');
389+
resolve('slave.js');
390+
}, 1);
391+
return slaveLocatePromise;
392+
}
393+
return oldLocate.apply(this, arguments);
394+
};
395+
396+
});
397+
398+
System.import('test/loader/master').then(function(m) {
399+
done()
400+
}, done).then(reset, reset);
401+
402+
function reset() {
403+
System.locate = oldLocate;
404+
}
405+
});
406+
407+
});
378408

379409
describeIf(
380410
typeof window != 'undefined' && window.Worker,

test/test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,34 @@ function runTests() {
441441
});
442442
});
443443

444+
test('should load System.define', function(assert) {
445+
var oldLocate = System.locate;
446+
var slaveLocatePromise = new Promise(function(resolve, reject) {
447+
448+
System.locate = function(load) {
449+
if(load.name === 'slave') {
450+
setTimeout(function() {
451+
System.define('slave', 'var double = [1,2,3].map(i => i * 2);');
452+
resolve('slave.js');
453+
}, 1);
454+
return slaveLocatePromise;
455+
}
456+
return oldLocate.apply(this, arguments);
457+
};
458+
459+
});
460+
461+
System.import('loader/master').then(function() {
462+
assert(true, true, 'Able to load');
463+
}, function(err) {
464+
assert('Did not resolve');
465+
}).then(reset, reset);
466+
467+
function reset() {
468+
System.locate = oldLocate;
469+
}
470+
});
471+
444472
var customModules = {};
445473
var customFactories = {};
446474

0 commit comments

Comments
 (0)