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