Browse Source

tidy up

better-aggressive
Rich-Harris 9 years ago
parent
commit
38374f1f93
  1. 5
      src/Bundle.js
  2. 25
      src/Module.js
  3. 16
      src/Statement.js

5
src/Bundle.js

@ -73,9 +73,8 @@ export default class Bundle {
declaration.use(); declaration.use();
}); });
this.modules.forEach( module => { // mark statements that should appear in the bundle
module.markAllSideEffects(); this.modules.forEach( module => module.markStatements() );
});
this.orderedModules = this.sort(); this.orderedModules = this.sort();
this.deconflict(); this.deconflict();

25
src/Module.js

@ -244,6 +244,7 @@ export default class Module {
const dependency = this.bundle.moduleById[ id ]; const dependency = this.bundle.moduleById[ id ];
if ( !dependency.isExternal ) { if ( !dependency.isExternal ) {
// TODO this is a weird data structure
weakDependencies[ dependency.id ] = dependency; weakDependencies[ dependency.id ] = dependency;
} }
}); });
@ -254,23 +255,6 @@ export default class Module {
} }
}); });
// // identify strong dependencies to break ties in case of cycles
// this.statements.forEach( statement => {
// statement.references.forEach( reference => {
// const declaration = reference.declaration;
//
// if ( declaration && declaration.statement ) {
// const module = declaration.statement.module;
// if ( module === this ) return;
//
// // TODO disregard function declarations
// if ( reference.isImmediatelyUsed ) {
// strongDependencies[ module.id ] = module;
// }
// }
// });
// });
return { strongDependencies, weakDependencies }; return { strongDependencies, weakDependencies };
} }
@ -294,15 +278,10 @@ export default class Module {
return keys( exports ); return keys( exports );
} }
markAllSideEffects () { markStatements () {
// console.group( this.id )
this.statements.forEach( statement => { this.statements.forEach( statement => {
statement.secondPass( this.strongDependencies ); statement.secondPass( this.strongDependencies );
}); });
// console.log( this.strongDependencies.map(m=>m.id) )
// console.groupEnd()
} }
namespace () { namespace () {

16
src/Statement.js

@ -157,26 +157,12 @@ export default class Statement {
} }
secondPass ( strongDependencies ) { secondPass ( strongDependencies ) {
// console.group( 'second pass: %s', this.toString() ) if ( this.isImportDeclaration || this.isFunctionDeclaration ) return;
// console.log( 'this.isIncluded', this.isIncluded )
// console.log( 'this.isImportDeclaration', this.isImportDeclaration )
// console.log( 'this.isFunctionDeclaration', this.isFunctionDeclaration )
if ( this.didSecondPassAlready || this.isImportDeclaration || this.isFunctionDeclaration ) {
// console.log( '>>> skipping' )
// console.groupEnd()
return;
}
this.didSecondPassAlready = true;
if ( testForSideEffects( this.node, this.scope, this, strongDependencies ) ) { if ( testForSideEffects( this.node, this.scope, this, strongDependencies ) ) {
this.mark(); this.mark();
// console.groupEnd()
return true; return true;
} }
// console.groupEnd()
} }
source () { source () {

Loading…
Cancel
Save