Browse Source

Avoid infinite recursion in Bundle.sort()

semi-dynamic-namespace-imports
ph.ter 8 years ago
committed by Philipp Weinfurter
parent
commit
088d12bf9f
  1. 8
      src/Bundle.js
  2. 11
      test/function/cycles-pathological-2/_config.js
  3. 11
      test/function/cycles-pathological-2/b.js
  4. 9
      test/function/cycles-pathological-2/c.js
  5. 7
      test/function/cycles-pathological-2/d.js
  6. 11
      test/function/cycles-pathological-2/main.js

8
src/Bundle.js

@ -422,15 +422,17 @@ export default class Bundle {
// b imports a, a is placed before b. We need to find the module
// in question, so we can provide a useful error message
let parent = '[[unknown]]';
const visited = {};
const findParent = module => {
if ( dependsOn[ module.id ][ a.id ] && dependsOn[ module.id ][ b.id ] ) {
parent = module.id;
} else {
return true;
}
visited[ module.id ] = true;
for ( let i = 0; i < module.dependencies.length; i += 1 ) {
const dependency = module.dependencies[i];
if ( findParent( dependency ) ) return;
}
if ( !visited[ dependency.id ] && findParent( dependency ) ) return true;
}
};

11
test/function/cycles-pathological-2/_config.js

@ -0,0 +1,11 @@
var assert = require( 'assert' );
module.exports = {
description: 'resolves even more pathological cyclical dependencies gracefully',
buble: true,
options: {
onwarn: function ( message ) {
assert.ok( /unable to evaluate without/.test( message ) );
}
}
};

11
test/function/cycles-pathological-2/b.js

@ -0,0 +1,11 @@
import { a, av } from './main';
import { d, dv } from './d';
import { c, cv } from './c';
export function b() {
a(av);
d(dv);
c(cv);
};
export const bv = av + dv + cv;

9
test/function/cycles-pathological-2/c.js

@ -0,0 +1,9 @@
import { b, bv } from './b';
import { a, av } from './main';
export function c() {
a(av);
b(bv);
};
export const cv = av + bv;

7
test/function/cycles-pathological-2/d.js

@ -0,0 +1,7 @@
import { c, cv } from './c';
export function d() {
c(cv);
};
export const dv = cv;

11
test/function/cycles-pathological-2/main.js

@ -0,0 +1,11 @@
import { b, bv } from './b';
import { d, dv } from './d';
import { c, cv } from './c';
export function a() {
b(bv);
d(dv);
c(cv);
};
export const av = bv + dv + cv;
Loading…
Cancel
Save