|
|
@ -49,11 +49,18 @@ export default class ExportDefaultDeclaration extends Node { |
|
|
|
const treeshake = this.module.bundle.treeshake; |
|
|
|
const name = this.getName( es ); |
|
|
|
|
|
|
|
// paren workaround: find first non-whitespace character position after `export default`
|
|
|
|
let declaration_start; |
|
|
|
if ( this.declaration ) { |
|
|
|
const statementStr = code.original.slice( this.start, this.end ); |
|
|
|
declaration_start = this.start + statementStr.match(/^export\s+default\s*/)[0].length; |
|
|
|
} |
|
|
|
|
|
|
|
if ( this.shouldInclude || this.declaration.activated ) { |
|
|
|
if ( this.activated ) { |
|
|
|
if ( functionOrClassDeclaration.test( this.declaration.type ) ) { |
|
|
|
if ( this.declaration.id ) { |
|
|
|
code.remove( this.start, this.declaration.start ); |
|
|
|
code.remove( this.start, declaration_start ); |
|
|
|
} else { |
|
|
|
throw new Error( 'TODO anonymous class/function declaration' ); |
|
|
|
} |
|
|
@ -65,14 +72,14 @@ export default class ExportDefaultDeclaration extends Node { |
|
|
|
code.remove( this.leadingCommentStart || this.start, this.next || this.end ); |
|
|
|
return; // don't render children. TODO this seems like a bit of a hack
|
|
|
|
} else { |
|
|
|
code.overwrite( this.start, this.declaration.start, `${this.module.bundle.varOrConst} ${name} = ` ); |
|
|
|
code.overwrite( this.start, declaration_start, `${this.module.bundle.varOrConst} ${name} = ` ); |
|
|
|
} |
|
|
|
|
|
|
|
this.insertSemicolon( code ); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// remove `var foo` from `var foo = bar()`, if `foo` is unused
|
|
|
|
code.remove( this.start, this.declaration.start ); |
|
|
|
code.remove( this.start, declaration_start ); |
|
|
|
} |
|
|
|
|
|
|
|
super.render( code, es ); |
|
|
@ -82,10 +89,10 @@ export default class ExportDefaultDeclaration extends Node { |
|
|
|
code.remove( this.leadingCommentStart || this.start, this.next || this.end ); |
|
|
|
} else { |
|
|
|
const hasEffects = this.declaration.hasEffects( this.module.scope ); |
|
|
|
code.remove( this.start, hasEffects ? this.declaration.start : this.next || this.end ); |
|
|
|
code.remove( this.start, hasEffects ? declaration_start : this.next || this.end ); |
|
|
|
} |
|
|
|
} else { |
|
|
|
code.overwrite( this.start, this.declaration.start, `${this.module.bundle.varOrConst} ${name} = ` ); |
|
|
|
code.overwrite( this.start, declaration_start, `${this.module.bundle.varOrConst} ${name} = ` ); |
|
|
|
} |
|
|
|
// code.remove( this.start, this.next || this.end );
|
|
|
|
} |
|
|
|