Browse Source

prevent stack overflow with mutual strong dependencies – fixes #425

gh-669
Rich Harris 9 years ago
parent
commit
389b10439b
  1. 8
      src/Bundle.js
  2. 3
      test/function/cycles-stack-overflow/_config.js
  3. 11
      test/function/cycles-stack-overflow/b.js
  4. 13
      test/function/cycles-stack-overflow/c.js
  5. 12
      test/function/cycles-stack-overflow/d.js
  6. 3
      test/function/cycles-stack-overflow/main.js

8
src/Bundle.js

@ -335,19 +335,25 @@ export default class Bundle {
let unordered = ordered;
ordered = [];
let placed = blank();
// unordered is actually semi-ordered, as [ fewer dependencies ... more dependencies ]
unordered.forEach( module => {
// ensure strong dependencies of `module` that don't strongly depend on `module` go first
strongDeps[ module.id ].forEach( place );
function place ( dep ) {
if ( !stronglyDependsOn[ dep.id ][ module.id ] && !~ordered.indexOf( dep ) ) {
if ( placed[ dep.id ] ) return;
placed[ dep.id ] = true;
if ( !stronglyDependsOn[ dep.id ][ module.id ] ) {
strongDeps[ dep.id ].forEach( place );
ordered.push( dep );
}
}
if ( !~ordered.indexOf( module ) ) {
placed[ module.id ] = true;
ordered.push( module );
}
});

3
test/function/cycles-stack-overflow/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'does not stack overflow on crazy cyclical dependencies'
};

11
test/function/cycles-stack-overflow/b.js

@ -0,0 +1,11 @@
import { C } from './c.js';
export function B () {};
B.prototype = {
c: function () {
return function () {
new C();
};
}()
};

13
test/function/cycles-stack-overflow/c.js

@ -0,0 +1,13 @@
import { D } from './d.js';
export function C () {
this.x = 'x';
}
C.prototype = {
d: function () {
return function () {
new D();
};
}()
};

12
test/function/cycles-stack-overflow/d.js

@ -0,0 +1,12 @@
import { B } from './b.js';
import { C } from './c.js';
export function D () {};
D.prototype = {
c: function () {
return function () {
new C();
};
}()
};

3
test/function/cycles-stack-overflow/main.js

@ -0,0 +1,3 @@
import { C } from './c.js';
assert.equal( new C().x, 'x' );
Loading…
Cancel
Save