Browse Source

Removed unused `findDefiningStatement`.

gh-109
Oskar Segersvärd 10 years ago
parent
commit
d8339d5697
  1. 21
      src/Bundle.js
  2. 5
      src/ExternalModule.js
  3. 34
      src/Module.js

21
src/Bundle.js

@ -137,15 +137,10 @@ export default class Bundle {
if ( statement.isIncluded ) return; if ( statement.isIncluded ) return;
keys( statement.modifies ).forEach( name => { keys( statement.modifies ).forEach( name => {
const definingStatement = module.definitions[ name ]; const local = module.locals.lookup( name );
const exportDeclaration = module.exports[ name ] || module.reexports[ name ] || ( const exported = module.exports.lookup( name );
module.exports.default && module.exports.default.identifier === name && module.exports.default
);
const shouldMark = ( definingStatement && definingStatement.isIncluded ) || if ( local && local.module === module || exported && exported.isUsed ) {
( exportDeclaration && exportDeclaration.isUsed );
if ( shouldMark ) {
settled = false; settled = false;
statement.mark(); statement.mark();
return; return;
@ -153,14 +148,8 @@ export default class Bundle {
// special case - https://github.com/rollup/rollup/pull/40 // special case - https://github.com/rollup/rollup/pull/40
// TODO refactor this? it's a bit confusing // TODO refactor this? it's a bit confusing
const importDeclaration = module.imports[ name ];
if ( !importDeclaration || importDeclaration.module.isExternal ) return;
const otherExportDeclaration = importDeclaration.module.exports[ importDeclaration.name ];
// TODO things like `export default a + b` don't apply here... right? // TODO things like `export default a + b` don't apply here... right?
const otherDefiningStatement = module.findDefiningStatement( otherExportDeclaration.localName ); if ( !local || !local.statement || !local.module || local.module.isExternal ) return;
if ( !otherDefiningStatement ) return;
settled = false; settled = false;
statement.mark(); statement.mark();
@ -230,7 +219,7 @@ export default class Bundle {
let magicString = new MagicString.Bundle({ separator: '\n\n' }); let magicString = new MagicString.Bundle({ separator: '\n\n' });
this.orderedModules.forEach( module => { this.orderedModules.forEach( module => {
const source = module.render( allBundleExports, format ); const source = module.render( allBundleExports, format === 'es6' );
if ( source.toString().length ) { if ( source.toString().length ) {
magicString.addSource( source ); magicString.addSource( source );
} }

5
src/ExternalModule.js

@ -17,6 +17,7 @@ export default class ExternalModule {
this.needsNamed = false; this.needsNamed = false;
this.needsAll = false; this.needsAll = false;
bundle.scope.define( this.name, this );
this.exports = bundle.scope.virtual(); this.exports = bundle.scope.virtual();
const ref = this.exports.reference; const ref = this.exports.reference;
@ -44,8 +45,4 @@ export default class ExternalModule {
return ref.call( this.exports, name ); return ref.call( this.exports, name );
}; };
} }
findDefiningStatement () {
return null;
}
} }

34
src/Module.js

@ -106,9 +106,9 @@ export default class Module {
// If the default export has an identifier, bind to it. // If the default export has an identifier, bind to it.
this.exports.bind( 'default', this.locals.reference( identifier ) ); this.exports.bind( 'default', this.locals.reference( identifier ) );
} else { } else {
this.exports.define( this.name, { this.exports.define( 'default', {
originalName: 'default', originalName: this.name,
name: 'default', name: this.name,
module: this, module: this,
statement, statement,
@ -328,12 +328,6 @@ export default class Module {
return this.name; return this.name;
} }
findDefiningStatement ( name ) {
if ( this.definitions[ name ] ) return this.definitions[ name ];
return null;
}
getModule ( source ) { getModule ( source ) {
return this.bundle.moduleById[ this.resolvedIds[ source ] ]; return this.bundle.moduleById[ this.resolvedIds[ source ] ];
} }
@ -488,7 +482,7 @@ export default class Module {
return statements; return statements;
} }
render ( toExport ) { render ( toExport, direct ) {
let magicString = this.magicString.clone(); let magicString = this.magicString.clone();
this.statements.forEach( statement => { this.statements.forEach( statement => {
@ -533,6 +527,18 @@ export default class Module {
let replacements = blank(); let replacements = blank();
let bundleExports = blank(); let bundleExports = blank();
// Indirect identifier access.
if ( !direct ) {
keys( statement.dependsOn )
.forEach( name => {
const id = this.locals.lookup( name );
if ( id.module && id.module.isExternal ) {
replacements[ name ] = `${id.module.name}.${id.originalName}`;
}
});
}
keys( statement.dependsOn ) keys( statement.dependsOn )
.concat( keys( statement.defines ) ) .concat( keys( statement.defines ) )
.forEach( name => { .forEach( name => {
@ -564,10 +570,10 @@ export default class Module {
const canonicalName = this.defaultName(); const canonicalName = this.defaultName();
// FIXME: dunno what to do here yet. // FIXME: dunno what to do here yet.
// if ( statement.node.declaration.type === 'Identifier' && canonicalName === ( moduleReplacements[ statement.node.declaration.name ] || statement.node.declaration.name ) ) { if ( statement.node.declaration.type === 'Identifier' && canonicalName === ( replacements[ statement.node.declaration.name ] || statement.node.declaration.name ) ) {
// magicString.remove( statement.start, statement.next ); magicString.remove( statement.start, statement.next );
// return; return;
// } }
// prevent `var undefined = sideEffectyDefault(foo)` // prevent `var undefined = sideEffectyDefault(foo)`
if ( canonicalName === undefined ) { if ( canonicalName === undefined ) {

Loading…
Cancel
Save