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

Commit dfa6bed

Browse files
committed
instead of exporter lock, use exporter cache as implicit lock mechanism, enabling full circlar reference binding update cases
1 parent 3808d4f commit dfa6bed

File tree

6 files changed

+36
-24
lines changed

6 files changed

+36
-24
lines changed

core/register-loader.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -326,35 +326,40 @@ function registerDeclarative (loader, load, link, declare) {
326326
var moduleObj = link.moduleObj;
327327
var importerSetters = load.importerSetters;
328328

329-
var locked = false;
329+
var definedExports = false;
330330

331331
// closure especially not based on link to allow link record disposal
332332
var declared = declare.call(global, function (name, value) {
333-
// export setter propogation with locking to avoid cycles
334-
if (locked)
335-
return;
336-
337333
if (typeof name === 'object') {
338-
for (var p in name)
339-
if (p !== '__useDefault')
340-
moduleObj[p] = name[p];
334+
var changed = false;
335+
for (var p in name) {
336+
value = name[p];
337+
if (p !== '__useDefault' && (!(p in moduleObj) || moduleObj[p] !== value)) {
338+
changed = true;
339+
moduleObj[p] = value;
340+
}
341+
}
342+
if (changed === false)
343+
return;
341344
}
342345
else {
346+
if ((definedExports || name in moduleObj) && moduleObj[name] === value)
347+
return;
343348
moduleObj[name] = value;
344349
}
345350

346-
locked = true;
347351
for (var i = 0; i < importerSetters.length; i++)
348352
importerSetters[i](moduleObj);
349-
locked = false;
350353

351354
return value;
352355
}, new ContextualLoader(loader, load.key));
353356

354357
link.setters = declared.setters;
355358
link.execute = declared.execute;
356-
if (declared.exports)
359+
if (declared.exports) {
357360
link.moduleObj = moduleObj = declared.exports;
361+
definedExports = true;
362+
}
358363
}
359364

360365
function instantiateDeps (loader, load, link, registry, state, seen) {

test/3-register-loader.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,16 @@ describe('System Register Loader', function() {
7777
var m1 = await loader.import('./register-modules/circular1.js');
7878
var m2 = await loader.import('./register-modules/circular2.js');
7979

80-
8180
assert.equal(m1.variable1, 'test circular 1');
8281
assert.equal(m2.variable2, 'test circular 2');
8382

8483
assert.equal(m2.output, 'test circular 1');
8584
assert.equal(m1.output, 'test circular 2');
8685
assert.equal(m2.output1, 'test circular 2');
8786
assert.equal(m1.output2, 'test circular 1');
87+
88+
assert.equal(m1.output1, 'test circular 2');
89+
assert.equal(m2.output2, 'test circular 1');
8890
});
8991

9092
it('should update circular dependencies', async function () {

test/fixtures/es-modules/circular1.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import {fn2, variable2} from './circular2.js';
22

33
export var variable1 = 'test circular 1';
44

5-
export { output as output2 } from './circular2.js';
6-
7-
fn2();
5+
export { output as output2, output1 } from './circular2.js';
86

97
export var output;
108

9+
fn2();
10+
1111
export function fn1() {
1212
output = variable2;
13-
}
13+
}

test/fixtures/es-modules/circular2.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import {fn1, variable1} from './circular1.js';
22

33
export var variable2 = 'test circular 2';
44

5-
export { output as output1 } from './circular1.js';
6-
7-
fn1();
5+
export { output as output1, output2 } from './circular1.js';
86

97
export var output;
108

9+
fn1();
10+
1111
export function fn2() {
1212
output = variable1;
13-
}
13+
}

test/fixtures/register-modules/circular1.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@ System.register(['./circular2.js'], function (_export, _context) {
66
_export('output', output = variable2);
77
}
88

9+
_export('fn1', fn1);
10+
911
return {
1012
exports: {
1113
fn1: fn1,
1214
variable1: undefined,
1315
output: undefined,
16+
output1: undefined,
1417
output2: undefined
1518
},
1619
setters: [function (_circular2Js) {
1720
fn2 = _circular2Js.fn2;
1821
variable2 = _circular2Js.variable2;
1922
var _exportObj = {};
2023
_exportObj.output2 = _circular2Js.output;
24+
_exportObj.output1 = _circular2Js.output1;
2125

2226
_export(_exportObj);
2327
}],
@@ -26,9 +30,9 @@ System.register(['./circular2.js'], function (_export, _context) {
2630

2731
_export('variable1', variable1);
2832

29-
fn2();
30-
3133
_export('output', output);
34+
35+
fn2();
3236
}
3337
};
3438
});

test/fixtures/register-modules/circular2.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ System.register(['./circular1.js'], function (_export, _context) {
1414
variable1 = _circular1Js.variable1;
1515
var _exportObj = {};
1616
_exportObj.output1 = _circular1Js.output;
17+
_exportObj.output2 = _circular1Js.output2;
1718

1819
_export(_exportObj);
1920
}],
@@ -22,9 +23,9 @@ System.register(['./circular1.js'], function (_export, _context) {
2223

2324
_export('variable2', variable2);
2425

25-
fn1();
26-
2726
_export('output', output);
27+
28+
fn1();
2829
}
2930
};
3031
});

0 commit comments

Comments
 (0)