Browse Source

more fixes

declarations-and-references
Rich-Harris 9 years ago
parent
commit
7159c791dc
  1. 4
      src/Bundle.js
  2. 6
      src/ExternalModule.js
  3. 21
      src/Module.js
  4. 4
      src/Statement.js
  5. 6
      src/ast/Scope.js

4
src/Bundle.js

@ -58,9 +58,7 @@ export default class Bundle {
const declaration = entryModule.traceExport( name );
declaration.isExported = true;
if ( declaration.statement ) {
declaration.statement.mark();
}
if ( declaration.statement ) declaration.use();
});
let settled = false;

6
src/ExternalModule.js

@ -6,8 +6,6 @@ class ExternalDeclaration {
this.module = module;
this.name = name;
this.isExternal = true;
this.references = [];
}
addReference ( reference ) {
@ -31,6 +29,10 @@ class ExternalDeclaration {
return es6 ? this.name : `${this.module.name}.${this.name}`;
}
use () {
// noop?
}
}
export default class ExternalModule {

21
src/Module.js

@ -14,12 +14,11 @@ class SyntheticDefaultDeclaration {
this.statement = statement;
this.name = name;
this.references = [];
this.original = null;
this.isExported = false;
}
addReference ( reference ) {
this.references.push( reference );
reference.declaration = this;
this.name = reference.name;
}
@ -33,6 +32,11 @@ class SyntheticDefaultDeclaration {
this.name :
this.original.render();
}
use () {
this.isUsed = true;
this.statement.mark();
}
}
class SyntheticNamespaceDeclaration {
@ -40,7 +44,6 @@ class SyntheticNamespaceDeclaration {
this.module = module;
this.name = null;
this.references = [];
this.needsNamespaceBlock = false;
this.originals = blank();
@ -72,12 +75,10 @@ class SyntheticNamespaceDeclaration {
keys( this.originals ).forEach( name => {
const original = this.originals[ name ];
original.statement.mark();
original.use();
});
}
this.references.push( reference );
reference.declaration = this;
this.name = reference.name;
}
@ -99,6 +100,10 @@ class SyntheticNamespaceDeclaration {
render () {
return this.name;
}
use () {
// noop
}
}
export default class Module {
@ -581,7 +586,7 @@ export default class Module {
const defaultName = defaultDeclaration.render();
// prevent `var undefined = sideEffectyDefault(foo)`
if ( !defaultDeclaration.isExported && !defaultDeclaration.references.length ) {
if ( !defaultDeclaration.isExported && !defaultDeclaration.isUsed ) {
magicString.remove( statement.start, statement.node.declaration.start );
return;
}

4
src/Statement.js

@ -155,9 +155,7 @@ export default class Statement {
this.isIncluded = true;
this.references.forEach( reference => {
if ( reference.declaration && reference.declaration.statement ) {
reference.declaration.statement.mark();
}
if ( reference.declaration ) reference.declaration.use();
});
}

6
src/ast/Scope.js

@ -35,7 +35,6 @@ function extractNames ( param ) {
class Declaration {
constructor () {
this.references = [];
this.statement = null;
this.name = null;
@ -55,6 +54,11 @@ class Declaration {
return `exports.${this.name}`;
}
use () {
this.isUsed = true;
if ( this.statement ) this.statement.mark();
}
}
export default class Scope {

Loading…
Cancel
Save