-
Notifications
You must be signed in to change notification settings - Fork 8
Description
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.