Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support export * as ns from "mod"; #3

Closed
demurgos opened this issue Aug 10, 2018 · 2 comments
Closed

Support export * as ns from "mod"; #3

demurgos opened this issue Aug 10, 2018 · 2 comments

Comments

@demurgos
Copy link

demurgos commented Aug 10, 2018

In the current spec and proposal, the symmetry between import and export is not complete. In particular, import * as ns from "mod"; does not have an equivalent export * as ns from "mod";.

The following table is presented at the bottom of the README:

Statement Form [[ModuleRequest]] [[ImportName]] [[LocalName]] [[ExportName]]
... ... ... ... ...
import * as ns from "mod"; "mod" "*" "ns"
export * from "mod"; "mod" "*" null null (many)

It seems to imply a symmetry, but there is none.
The export * from "mod" is the only form where the information about the names is non-local and depends on the exported names of another module (you can't know what is actually exported unless you look into "mod"). The equivalent form would be an import * from "mod"; importing many names. This kind of form can cause breaking changes if the dependencies are updated and export new names that collide. Requiring a local name on import (as ns) prevents these collisions. There should be a symmetric safe export allowing you to export the the mod namespace under a single name: export * as ns from "mod".

Reexporting a whole module is common if you want to create a library with a single entry point that reexports the value of its internal modules.

Here is an existing example:

import * as errors from "./errors";
export {errors};

It should be possible to rewrite it without introducing a local name:

export * as errors from "./errors";

Here is a real world example that could be simplified.

@ljharb
Copy link
Member

ljharb commented Aug 10, 2018

That is already a needs-consensus PR: tc39/ecma262#1174

@demurgos
Copy link
Author

demurgos commented Aug 10, 2018

Thanks for the link.

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

No branches or pull requests

2 participants