diff --git a/src/Bundle.js b/src/Bundle.js index 0f46380..7b937d4 100644 --- a/src/Bundle.js +++ b/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 { - for ( let i = 0; i < module.dependencies.length; i += 1 ) { - const dependency = module.dependencies[i]; - if ( findParent( dependency ) ) return; - } + return true; + } + visited[ module.id ] = true; + for ( let i = 0; i < module.dependencies.length; i += 1 ) { + const dependency = module.dependencies[i]; + if ( !visited[ dependency.id ] && findParent( dependency ) ) return true; } }; diff --git a/test/function/cycles-pathological-2/_config.js b/test/function/cycles-pathological-2/_config.js new file mode 100644 index 0000000..87ba7d6 --- /dev/null +++ b/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 ) ); + } + } +}; diff --git a/test/function/cycles-pathological-2/b.js b/test/function/cycles-pathological-2/b.js new file mode 100644 index 0000000..1a4723b --- /dev/null +++ b/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; diff --git a/test/function/cycles-pathological-2/c.js b/test/function/cycles-pathological-2/c.js new file mode 100644 index 0000000..da8f42e --- /dev/null +++ b/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; diff --git a/test/function/cycles-pathological-2/d.js b/test/function/cycles-pathological-2/d.js new file mode 100644 index 0000000..b7d9f07 --- /dev/null +++ b/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; diff --git a/test/function/cycles-pathological-2/main.js b/test/function/cycles-pathological-2/main.js new file mode 100644 index 0000000..06bcc6e --- /dev/null +++ b/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;