Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I change the name of an export in es6 module?

Tags:

ecmascript-6

I'm using es6 and therefore don't have class decorators. If I had class decorators I would do this:

@b
export class A {}

which would mean b(A) would be exported as A

However I don't have decorators so I have to do something like this:

class A {}
export const C = b(A)

but now my module exports b(A) as C but I want it to be exported as A.

Is there a way to change the name as I'm exporting to make this work?

like image 940
Jack Allan Avatar asked Apr 06 '16 22:04

Jack Allan


1 Answers

You can choose a different name using export { ... } syntax.

class A {}
const C = b(A)
export {C as A};

You could also potentially do

export const A = b(class A { });
like image 85
loganfsmyth Avatar answered Sep 16 '22 22:09

loganfsmyth