Proposal: export ** from './FooBar'

Jordan Harband ljharb at gmail.com
Sun Mar 3 06:17:04 UTC 2019


https://github.com/tc39/ecma262/pull/1174 adds `export * as someName from
'path'`; https://github.com/tc39/proposal-export-default-from is the
proposal that you're looking for.

On Fri, Mar 1, 2019 at 6:48 AM Mike Samuel <mikesamuel at gmail.com> wrote:

>
>
> On Fri, Mar 1, 2019 at 1:35 AM Cyril Auburtin <cyril.auburtin at gmail.com>
> wrote:
>
>> 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
> https://html.spec.whatwg.org/multipage/webappapis.html#hostgetimportmetaproperties
> 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
> HostGetMetaProperties(?).
>
> 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 mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190302/0b7de8da/attachment.html>


More information about the es-discuss mailing list