archives

« Bugzilla Issues Index

#2986 — Default default to object with exports


Now that the module-style imports are gone/will be gone, it would be great to still have a clean way of handling many imports. The suggested solution using System.get is a very obvious hack. How about the following rule: If a module doesn't have a default export, the default exports defaults to an object with all exports.

E.g. if I have a module "fs" that exports many functions but doesn't have a default exports, it should be legal to do either:

```
import FS from 'fs';
```

Or:

```
import { readFile, createWriteStream } from 'fs';
```

Modules that only export one thing could still use an explicit default export while those with many exports don't have to go for the more verbose:

```
export function readFile() {}
export function createWriteStream() {}

export default { readFile, createWriteStream };
```


That is a refactor hazard.

If the module suddenly adds a default export then you get no compile error but things fail at runtime (if you are unlucky it will only fail when your customer wants to pay you).