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
  4. 2
      src/ast/isFunctionDeclaration.js

5
src/Bundle.js

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

25
src/Module.js

@ -244,6 +244,7 @@ export default class Module {
const dependency = this.bundle.moduleById[ id ];
if ( !dependency.isExternal ) {
// TODO this is a weird data structure
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 };
}
@ -294,15 +278,10 @@ export default class Module {
return keys( exports );
}
markAllSideEffects () {
// console.group( this.id )
markStatements () {
this.statements.forEach( statement => {
statement.secondPass( this.strongDependencies );
});
// console.log( this.strongDependencies.map(m=>m.id) )
// console.groupEnd()
}
namespace () {

16
src/Statement.js

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

2
src/ast/isFunctionDeclaration.js

@ -1,6 +1,6 @@
export default function isFunctionDeclaration ( node ) {
if ( !node ) return false;
return node.type === 'FunctionDeclaration' ||
( node.type === 'VariableDeclaration' && node.init && /FunctionExpression/.test( node.init.type ) );
}

Loading…
Cancel
Save