import { foo, bar } as obj from 'module

Jérémy Judéaux jeremy.judeaux at volune.net
Sat Dec 16 04:40:46 UTC 2017


One of the first assumptions in this discussion is that “Star imports prevent treeshaking”

But thinking about it, I don’t see why tools cannot transform
```js
import * as L from './lib';
console.log(L.foo, L.bar());
```
To
```js
import {foo as $$generated$$1$$foo$$, bar as $$generated$$1$$bar$$} from './lib';
console.log($$generated$$1$$foo$$, $$generated$$1$$bar$$());
```
And then apply tree-shaking. As long as the code doesn’t contain something like `Object.keys(L)` it should be fine.

At least that’s for the concept, maybe tools have better ways to do it.
So I tried, webpack 3 + babel 7 beta. And it works. A very big function I put inside my lib.js only get exported if I use `Object.keys(L)`

With treeshaking working with star imports, are there still benefits of the proposed syntax?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20171216/9e690254/attachment-0001.html>


More information about the es-discuss mailing list