|
|
@ -16,6 +16,11 @@ class SyntheticDefaultDeclaration { |
|
|
|
|
|
|
|
this.original = null; |
|
|
|
this.isExported = false; |
|
|
|
this.aliases = []; |
|
|
|
} |
|
|
|
|
|
|
|
addAlias ( declaration ) { |
|
|
|
this.aliases.push( declaration ); |
|
|
|
} |
|
|
|
|
|
|
|
addReference ( reference ) { |
|
|
@ -36,6 +41,8 @@ class SyntheticDefaultDeclaration { |
|
|
|
use () { |
|
|
|
this.isUsed = true; |
|
|
|
this.statement.mark(); |
|
|
|
|
|
|
|
this.aliases.forEach( alias => alias.use() ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -45,6 +52,7 @@ class SyntheticNamespaceDeclaration { |
|
|
|
this.name = null; |
|
|
|
|
|
|
|
this.needsNamespaceBlock = false; |
|
|
|
this.aliases = []; |
|
|
|
|
|
|
|
this.originals = blank(); |
|
|
|
module.getExports().forEach( name => { |
|
|
@ -52,6 +60,10 @@ class SyntheticNamespaceDeclaration { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
addAlias ( declaration ) { |
|
|
|
this.aliases.push( declaration ); |
|
|
|
} |
|
|
|
|
|
|
|
addReference ( reference ) { |
|
|
|
// if we have e.g. `foo.bar`, we can optimise
|
|
|
|
// the reference by pointing directly to `bar`
|
|
|
@ -102,7 +114,8 @@ class SyntheticNamespaceDeclaration { |
|
|
|
} |
|
|
|
|
|
|
|
use () { |
|
|
|
// noop
|
|
|
|
// noop?
|
|
|
|
this.aliases.forEach( alias => alias.use() ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -287,6 +300,21 @@ export default class Module { |
|
|
|
return makeLegalIdentifier( basename( this.id ).slice( 0, -extname( this.id ).length ) ); |
|
|
|
} |
|
|
|
|
|
|
|
bindAliases () { |
|
|
|
keys( this.declarations ).forEach( name => { |
|
|
|
const declaration = this.declarations[ name ]; |
|
|
|
const statement = declaration.statement; |
|
|
|
if ( statement.node.type !== 'VariableDeclaration' ) return; |
|
|
|
|
|
|
|
statement.references.forEach( reference => { |
|
|
|
if ( reference.name === name || !reference.isImmediatelyUsed ) return; |
|
|
|
|
|
|
|
const otherDeclaration = this.trace( reference.name ); |
|
|
|
if ( otherDeclaration ) otherDeclaration.addAlias( declaration ); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
bindImportSpecifiers () { |
|
|
|
[ this.imports, this.reexports ].forEach( specifiers => { |
|
|
|
keys( specifiers ).forEach( name => { |
|
|
|