Proposal: Discarding specific element when importing/re-exporting module

Cyril Auburtin cyril.auburtin at gmail.com
Fri Nov 1 09:00:59 UTC 2019


It's also possible to split that large 'A' file in 2, and have a possible
third file merging them

```js
export * from './numbers.js'
export * from './A-without-numbers.js'
```

On Sun, Oct 27, 2019 at 6:39 AM Sm In <sbshw1 at gmail.com> wrote:

> # Proposal: `except` clause in ModuleItem
>
> Inspired by [Haskell’s import statement](https://wiki.haskell.org/Import)
>
> ## Concept Introduction
>
> Let’s say we have module A:
>
> ```js
> // A.js
> export const zero = 0;
> export const one = 1;
> export const two = 2;
> export const three = 3;
> export const four = 4;
> // …
> export const ten = 10;
> ```
>
> A has so many exported values.
> Now Let’s say we want to re-export numbers between 0 to 9 in module B.
>
> ```js
> // B.js
> export { zero, one, two, three, four, five, six, seven, eight, nine } from
> ‘./A.js’;
> ```
>
> Hmmm, This is too long to see, isn’t it?
> How can we reduce this long, long export declaration?
> “Exporting numbers between 0 to 9 in module B” is same statement as
> “Exporting everything except ten from module B”.
> So, what if we can rewrite export declaration above like this?:
>
> ```js
> //B.js
> export * except { ten } from ‘./A.js’;
> ```
>
> This would be not only simpler way but also shorter way.
>
> ## Uses cases
>
> When dealing with module that has too many exports to explicitly specify.
> I.e when using Util libraries or functional programming libraries like
> ramda, lodash, fp-ts and etc.
>
> ## Non-Formal shapes
>
> ```
> Import * except { elements… } from ‘module’;
>
> Export * except { elements… } from ‘module’;
> ```
>
> _______________________________________________
> 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/20191101/f3592dc9/attachment.html>


More information about the es-discuss mailing list