Proposal: export ** from './FooBar'

Mike Samuel mikesamuel at
Fri Mar 1 14:48:07 UTC 2019

On Fri, Mar 1, 2019 at 1:35 AM Cyril Auburtin <cyril.auburtin at>

> Sometimes, (particularly in React codebases) you have to write many lines
> like:
> ```js
> export { default as FooBar } from './FooBar';
> ```
> It could be automated of course
> It could also be tuned into
> ```js
> export * from './FooBar';
> ```
> only if FooBar is also a named export in that file, but usually files with
> one export just use a default export
> ------
> This proposed syntax:
> ```js
> export ** from './FooBar';
> ```
> Would do:
> ```js
> export * from './FooBar';
> export { default as FooBar } from './FooBar';
> ```
> the filename is used as default export name.
> If the filename isn't a valid JS identifier, like 'foo-bar' for example,
> it would throw

ES doesn't impose many constraints on the string content of a module
specifier but in practice it maps fairly directly to a URL per
so filename is probably broadly available.

Would this use the filename from the module specifier or from the URL
(assuming import.meta.url)?
IIRC, only the module specifier is available within ES currently.
The translation between specifiers and URLs (if that happens) is up to a
host callback (HostResolveImportedModule) and does not surface inside the
ES engine.
That import.meta.url exists is up to another host callback so assuming it's
existence might require constraining host implementations of

What would this do when import.meta.url/specifier has a query part, or that
look like a non-hierarchical URL?
    export ** from "path?foo=bar";
    export ** from "?foo=bar";
    export ** from "data:application/javascript+module,export default null;"

Does anyone know if existing CDNs use the path component for something
other than the path contributed by the uploader and expect the original
filename in the query, like
host.cdn/path/to/tarball?p=path/within/tarball.js ?

> _______________________________________________
> es-discuss mailing list
> es-discuss at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list