From ac25ad5f4c489c1b7159428d962cb55a1ceaef35 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sat, 3 Oct 2015 22:43:03 -0400 Subject: [PATCH] handle pathological cycles --- src/Bundle.js | 5 ++++- src/Module.js | 14 ++++++++++++-- test/function/consistent-renaming-c/_config.js | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Bundle.js b/src/Bundle.js index f8408cc..4fa9e4f 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -68,7 +68,10 @@ export default class Bundle { entryModule.getExports().forEach( name => { const declaration = entryModule.traceExport( name ); declaration.isExported = true; - declaration.statement.mark(); + + if ( declaration.statement ) { + declaration.statement.mark(); + } }); this.markAllModifierStatements(); diff --git a/src/Module.js b/src/Module.js index 9569878..c9179df 100644 --- a/src/Module.js +++ b/src/Module.js @@ -254,9 +254,19 @@ export default class Module { this.statements.forEach( statement => { statement.references.forEach( reference => { - if ( reference.declaration && reference.declaration.statement ) { - const module = reference.declaration.statement.module; + const declaration = reference.declaration; + + if ( declaration && declaration.statement ) { + const module = declaration.statement.module; + if ( module === this ) return; + weakDependencies[ module.id ] = module; + + // TODO handle references inside IIFEs, and disregard + // function declarations + if ( !reference.scope.parent ) { + strongDependencies[ module.id ] = module; + } } }); }); diff --git a/test/function/consistent-renaming-c/_config.js b/test/function/consistent-renaming-c/_config.js index ad1b3a9..4b30d56 100644 --- a/test/function/consistent-renaming-c/_config.js +++ b/test/function/consistent-renaming-c/_config.js @@ -1,3 +1,3 @@ module.exports = { description: 'consistent renaming test c' -}; \ No newline at end of file +};