Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Resolve presets with named exports correctly#4620

Merged
hzoo merged 1 commit into
babel:masterfrom
danez:fix-es-presets
Sep 30, 2016
Merged

Resolve presets with named exports correctly#4620
hzoo merged 1 commit into
babel:masterfrom
danez:fix-es-presets

Conversation

@danez
Copy link
Copy Markdown
Member

@danez danez commented Sep 30, 2016

Q A
Bug fix? yes
Breaking change? no
New feature? no
Deprecations? no
Spec compliancy? no
Tests added/pass? yes
Fixed tickets #4608, #4592
License MIT
Doc PR

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:

  • If preset has a default export use it and ignore all other named exports (export default)
  • Else use all named exports and treat them as the exported configuration (export const plugins ...)
  • If the resulting object has a buildPreset function then use it to create the preset (This accounts for export default { buildPreset } and export const buildPreset and 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.

@danez danez added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Sep 30, 2016
} else {
// If there is no default export we treat all named exports as options
// and just remove the __esModule
const { __esModule:_, ...rest } = val;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hitting no-unused-vars with babel/babel-eslint#95

292:32 error '_' is defined but never used no-unused-vars

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always thought this is the way it works with eslint now to ignore variables in destructing. hhmmm..

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it was updated in the major version since we are still on node 0.10

@codecov-io
Copy link
Copy Markdown

codecov-io commented Sep 30, 2016

Current coverage is 88.80% (diff: 100%)

Merging #4620 into master will increase coverage by 0.07%

@@             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          

Powered by Codecov. Last update 1d72875...0799e3c

if (val.default) {
val = val.default;
} else {
// If there is no default export we treat all named exports as options
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, can we add a note here that this is deprecated and should not be used?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like a console.warn or just a comment

Copy link
Copy Markdown
Member Author

@danez danez Sep 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we support returning a default export that is either an object or a function? I add a comment.

@loganfsmyth
Copy link
Copy Markdown
Member

Sounds good to me, thanks so much for adding all those tests, especially.

@hzoo hzoo merged commit 4633946 into babel:master Sep 30, 2016
@danez danez deleted the fix-es-presets branch November 26, 2016 18:39
panagosg7 pushed a commit to panagosg7/babel that referenced this pull request Jan 17, 2017
@hzoo hzoo mentioned this pull request Oct 5, 2017
@lock lock Bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 7, 2019
@lock lock Bot locked as resolved and limited conversation to collaborators Oct 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants