Browse Source

more fixes

declarations-and-references
Rich-Harris 9 years ago
parent
commit
d22f0cdf5a
  1. 37
      src/Bundle.js
  2. 11
      src/Module.js
  3. 3
      src/Statement.js

37
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';

11
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;

3
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;

Loading…
Cancel
Save