I'm wanting to programmatically generate the exports for a module, is this possible in es6?
Something along these lines:
const ids = ['foo', 'bar', 'baz'];
ids.forEach(id => {
export const [id.toUpperCase()] = id;
});
No, it's not. Exports and imports are required to be statically analysable in ES6 modules.
Not only is that no-top-level export declaration a syntax error, but also your attempt at declaring variables with dynamic names. The bracket notation is reserved for computed properties only.
So if you are going to programmatically generate module exports, you'll need to dynamically generate the module source text (as a part of your build process).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With