Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

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

Closed
robpalme opened this issue Sep 20, 2017 · 3 comments
Closed

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

robpalme opened this issue Sep 20, 2017 · 3 comments

Comments

@robpalme
Copy link

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?

@ExE-Boss
Copy link

ExE-Boss commented Jun 22, 2019

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

@ljharb
Copy link
Member

ljharb commented Jun 22, 2019

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

@spectranaut
Copy link
Collaborator

@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 🎉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants