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

Sm In sbshw1 at gmail.com
Sun Oct 27 05:39:15 UTC 2019


# Proposal: `except` clause in ModuleItem

Inspired by [Haskell’s import statement](https://wiki.haskell.org/Import <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’;
```

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20191027/2144e8c5/attachment.html>


More information about the es-discuss mailing list