tc39 / proposal-export-ns-from

Proposal to add `export * as ns from "mod";` to ECMAScript.

Home Page:https://tc39.github.io/proposal-export-ns-from/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inverse operation: export { ns as * } from "x"

robpalme opened this issue · comments

First thing: I realize this is somewhat hijacking the proposal's repo, so will close immediately if you feel it's too off-topic, but it seems a directly related extension (symmetry/completeness of the export syntax) and I wish to research it without pitching a proposal.

This (now accepted) proposal (export * as ns from "x") gives us the ability to easily re-export and aggregate multiple child modules as named exports of a parent module. Specifically, it allows doing so without needing to know or specify the exports contained in those child modules, by virtue of using namespaces. It permits bundling/multiplexing, in a sense. Where the child module names are explicit but the exports they contain are implicit.

// parent-aggregator.js
export * as child1ns from "child1.js"
export * as child2ns from "child2.js"

There is currently no way of performing the inverse operation: destructuring those aggregated modules from the parent module back out to individually named modules. It can only be done if you explicitly name the exports inside the child modules. I'm thinking of something that would allow:

// child1-proxy.js
export { child1ns as * } from "parent-aggregator.js"
// child2-proxy.js
export { child2ns as * } from "parent-aggregator.js"

Has there been any discussion or ideas on this? Do you think it has merit pursuing?

This is out of scope and would require dynamic modules, which probably won’t be a part of the ECMA‑262 standard.

I don’t think it would require dynamic modules at all.

@robpalme if you are still interested in this suggestion, please open as a new proposal for feedback :)

Closing because the consensus PR was merged: tc39/ecma262#1174 🎉