Resolve presets with named exports correctly#4620
Conversation
| } else { | ||
| // If there is no default export we treat all named exports as options | ||
| // and just remove the __esModule | ||
| const { __esModule:_, ...rest } = val; |
There was a problem hiding this comment.
Hitting no-unused-vars with babel/babel-eslint#95
292:32 error '_' is defined but never used no-unused-vars
There was a problem hiding this comment.
I always thought this is the way it works with eslint now to ignore variables in destructing. hhmmm..
There was a problem hiding this comment.
maybe it was updated in the major version since we are still on node 0.10
Current coverage is 88.80% (diff: 100%)@@ master #4620 diff @@
==========================================
Files 195 195
Lines 13761 13860 +99
Methods 1424 1440 +16
Messages 0 0
Branches 3169 3226 +57
==========================================
+ Hits 12211 12309 +98
- Misses 1550 1551 +1
Partials 0 0
|
| if (val.default) { | ||
| val = val.default; | ||
| } else { | ||
| // If there is no default export we treat all named exports as options |
There was a problem hiding this comment.
Sounds good, can we add a note here that this is deprecated and should not be used?
There was a problem hiding this comment.
Like a console.warn or just a comment
There was a problem hiding this comment.
So we support returning a default export that is either an object or a function? I add a comment.
|
Sounds good to me, thanks so much for adding all those tests, especially. |
Some plugins export the config with named exports like this preset: https://github.com/chpio/babel-preset-bluebird/blob/master/main.es2015.js
This wasn't working as we were assuming that if preset === es-module then it needs to have a default export.
The patch simply corrects this behaviour and does this in order:
export default)export const plugins ...)buildPresetfunction then use it to create the preset (This accounts forexport default { buildPreset }andexport const buildPresetand es5)The tests should account for most preset formats now. The only bad thing is that the fixture presets are transpiled by hands. So if we change babel they wont change, but we can probably solve that when we improved babel-register.