diff --git a/src/Bundle.js b/src/Bundle.js index 8bc5826..4130909 100644 --- a/src/Bundle.js +++ b/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(); diff --git a/src/Module.js b/src/Module.js index b21b37d..b777ea6 100644 --- a/src/Module.js +++ b/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 () { diff --git a/src/Statement.js b/src/Statement.js index fe5c7b7..00e0fcc 100644 --- a/src/Statement.js +++ b/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 () { diff --git a/src/ast/isFunctionDeclaration.js b/src/ast/isFunctionDeclaration.js index 02af498..a1573e7 100644 --- a/src/ast/isFunctionDeclaration.js +++ b/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 ) ); }