0

Is it possible to export a constant with a dynamic name in es6?

e.g:

const NAME = 'abc';
const foo = 'bar';
export {foo as NAME}
davegri
  • 2,206
  • 2
  • 26
  • 45
  • 2
    Can't do, ES6 modules are static. – elclanrs Mar 21 '16 at 16:45
  • why not import it as whatever you want to call it? – omarjmh Mar 21 '16 at 16:48
  • @elclanrs is correct, the ES2015 module spec is specifically designed to not allow for dynamic imports and exports. There are good reasons for this: http://calculist.org/blog/2012/06/29/static-module-resolution/ – Joe Clay Mar 21 '16 at 16:50
  • Why would you want to do that anyway? What is your problem? Wouldn't this complicate the import if the name was changing? – Bergi Mar 21 '16 at 17:07

0 Answers0