From d22f0cdf5a565141a97abc37ccf15c25cdf4c499 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sun, 4 Oct 2015 00:21:44 -0400 Subject: [PATCH] more fixes --- src/Bundle.js | 37 ++++++++++--------------------------- src/Module.js | 11 +++++++++++ src/Statement.js | 3 +++ 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/Bundle.js b/src/Bundle.js index 4fa9e4f..4255728 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -50,19 +50,8 @@ export default class Bundle { .then( entryModule => { this.entryModule = entryModule; - this.modules.forEach( module => { - module.bindImportSpecifiers(); - module.bindReferences(); - }); - - let settled = false; - while ( !settled ) { - settled = true; - - this.modules.forEach( module => { - if ( module.markAllSideEffects() ) settled = false; - }); - } + this.modules.forEach( module => module.bindImportSpecifiers() ); + this.modules.forEach( module => module.bindReferences() ); // mark all export statements entryModule.getExports().forEach( name => { @@ -74,7 +63,14 @@ export default class Bundle { } }); - this.markAllModifierStatements(); + let settled = false; + while ( !settled ) { + settled = true; + + this.modules.forEach( module => { + if ( module.markAllSideEffects() ) settled = false; + }); + } this.orderedModules = this.sort(); this.deconflict(); @@ -164,19 +160,6 @@ export default class Bundle { return Promise.all( promises ); } - markAllModifierStatements () { - let settled = true; - - this.modules.forEach( module => { - module.statements.forEach( statement => { - if ( statement.isIncluded ) return; - // TODO... - }); - }); - - if ( !settled ) this.markAllModifierStatements(); - } - render ( options = {} ) { const format = options.format || 'es6'; diff --git a/src/Module.js b/src/Module.js index d9ba8be..bac0093 100644 --- a/src/Module.js +++ b/src/Module.js @@ -434,6 +434,17 @@ export default class Module { } } + // split up/remove var declarations as necessary + if ( statement.node.isSynthetic ) { + // insert `var/let/const` if necessary + const declaration = this.declarations[ statement.node.declarations[0].id.name ]; + if ( !declaration.isExported ) { + magicString.insert( statement.start, `${statement.node.kind} ` ); + } + + magicString.overwrite( statement.end, statement.next, ';\n' ); // TODO account for trailing newlines + } + statement.references.forEach( reference => { const declaration = reference.declaration; diff --git a/src/Statement.js b/src/Statement.js index 5f5b5b5..d65414b 100644 --- a/src/Statement.js +++ b/src/Statement.js @@ -18,6 +18,9 @@ function isReference ( node, parent ) { } if ( node.type === 'Identifier' ) { + // TODO is this right? + if ( parent.type === 'MemberExpression' ) return node === parent.object; + // disregard the `bar` in { bar: foo } if ( parent.type === 'Property' && node !== parent.value ) return false;