Browse Source

simplify consolidateDependencies

better-aggressive
Rich-Harris 9 years ago
parent
commit
7b57720d13
  1. 12
      src/Bundle.js
  2. 16
      src/Module.js
  3. 2
      src/utils/run.js

12
src/Bundle.js

@ -274,12 +274,10 @@ export default class Bundle {
strongDeps[ module.id ] = [];
stronglyDependsOn[ module.id ] = {};
keys( strongDependencies ).forEach( id => {
const imported = strongDependencies[ id ];
strongDependencies.forEach( imported => {
strongDeps[ module.id ].push( imported );
if ( seen[ id ] ) {
if ( seen[ imported.id ] ) {
// we need to prevent an infinite loop, and note that
// we need to check for strong/weak dependency relationships
hasCycles = true;
@ -289,10 +287,8 @@ export default class Bundle {
visit( imported );
});
keys( weakDependencies ).forEach( id => {
const imported = weakDependencies[ id ];
if ( seen[ id ] ) {
weakDependencies.forEach( imported => {
if ( seen[ imported.id ] ) {
// we need to prevent an infinite loop, and note that
// we need to check for strong/weak dependency relationships
hasCycles = true;

16
src/Module.js

@ -238,25 +238,21 @@ export default class Module {
}
consolidateDependencies () {
let strongDependencies = blank();
let weakDependencies = blank();
let strongDependencies = [];
let weakDependencies = [];
// treat all imports as weak dependencies
this.dependencies.forEach( source => {
const id = this.resolvedIds[ source ];
const dependency = this.bundle.moduleById[ id ];
if ( !dependency.isExternal ) {
// TODO this is a weird data structure
weakDependencies[ dependency.id ] = dependency;
if ( !dependency.isExternal && !~weakDependencies.indexOf( dependency ) ) {
weakDependencies.push( dependency );
}
});
this.strongDependencies.forEach( module => {
if ( module !== this ) {
strongDependencies[ module.id ] = module;
}
});
strongDependencies = this.strongDependencies
.filter( module => module !== this );
return { strongDependencies, weakDependencies };
}

2
src/utils/run.js

@ -30,7 +30,7 @@ export default function run ( node, scope, statement, strongDependencies, force
const declaration = statement.module.trace( flattened.name );
if ( declaration && !declaration.isExternal ) {
const module = declaration.module || declaration.statement.module; // TODO is this right?
if ( !~strongDependencies.indexOf( module ) ) strongDependencies.push( module );
if ( !module.isExternal && !~strongDependencies.indexOf( module ) ) strongDependencies.push( module );
}
}
}

Loading…
Cancel
Save