|
@ -1,17 +1,59 @@ |
|
|
|
|
|
import { find } from '../../utils/array.js'; |
|
|
import Node from '../Node.js'; |
|
|
import Node from '../Node.js'; |
|
|
|
|
|
|
|
|
|
|
|
class UnboundDefaultExport { |
|
|
|
|
|
constructor ( original ) { |
|
|
|
|
|
this.original = original; |
|
|
|
|
|
this.name = original.name; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
activate () { |
|
|
|
|
|
if ( this.activated ) return; |
|
|
|
|
|
this.activated = true; |
|
|
|
|
|
|
|
|
|
|
|
this.original.activate(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
addReference ( reference ) { |
|
|
|
|
|
this.name = reference.name; |
|
|
|
|
|
this.original.addReference( reference ); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bind ( scope ) { |
|
|
|
|
|
this.original.bind( scope ); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
gatherPossibleValues ( values ) { |
|
|
|
|
|
this.original.gatherPossibleValues( values ); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getName ( es ) { |
|
|
|
|
|
if ( this.original && !this.original.isReassigned ) { |
|
|
|
|
|
return this.original.getName( es ); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return this.name; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
export default class ExportNamedDeclaration extends Node { |
|
|
export default class ExportNamedDeclaration extends Node { |
|
|
initialise ( scope ) { |
|
|
initialise ( scope ) { |
|
|
|
|
|
this.scope = scope; |
|
|
this.isExportDeclaration = true; |
|
|
this.isExportDeclaration = true; |
|
|
if ( this.declaration ) { |
|
|
|
|
|
this.declaration.initialise( scope ); |
|
|
// special case – `export { foo as default }` should not create a live binding
|
|
|
|
|
|
const defaultExport = find( this.specifiers, specifier => specifier.exported.name === 'default' ); |
|
|
|
|
|
if ( defaultExport ) { |
|
|
|
|
|
const declaration = this.scope.findDeclaration( defaultExport.local.name ); |
|
|
|
|
|
this.defaultExport = new UnboundDefaultExport( declaration ); |
|
|
|
|
|
scope.declarations.default = this.defaultExport; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ( this.declaration ) this.declaration.initialise( scope ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bind ( scope ) { |
|
|
bind ( scope ) { |
|
|
if ( this.declaration ) { |
|
|
if ( this.declaration ) this.declaration.bind( scope ); |
|
|
this.declaration.bind( scope ); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
render ( code, es ) { |
|
|
render ( code, es ) { |
|
@ -19,7 +61,20 @@ export default class ExportNamedDeclaration extends Node { |
|
|
code.remove( this.start, this.declaration.start ); |
|
|
code.remove( this.start, this.declaration.start ); |
|
|
this.declaration.render( code, es ); |
|
|
this.declaration.render( code, es ); |
|
|
} else { |
|
|
} else { |
|
|
code.remove( this.leadingCommentStart || this.start, this.next || this.end ); |
|
|
const start = this.leadingCommentStart || this.start; |
|
|
|
|
|
const end = this.next || this.end; |
|
|
|
|
|
|
|
|
|
|
|
if ( this.defaultExport ) { |
|
|
|
|
|
const name = this.defaultExport.getName( es ); |
|
|
|
|
|
const originalName = this.defaultExport.original.getName( es ); |
|
|
|
|
|
|
|
|
|
|
|
if ( name !== originalName ) { |
|
|
|
|
|
code.overwrite( start, end, `var ${name} = ${originalName};` ); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
code.remove( start, end ); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|