Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export Helpers #613

Merged
merged 1 commit into from
Apr 29, 2019
Merged

Export Helpers #613

merged 1 commit into from
Apr 29, 2019

Conversation

casesandberg
Copy link
Owner

@casesandberg casesandberg commented Apr 29, 2019

This PR gives access to the internal helper functions we use:

import { getContrastingColor } from 'react-color/lib/helpers'

Closes #498

@casesandberg casesandberg merged commit f34fb60 into master Apr 29, 2019
@@ -70,3 +68,5 @@ export const red = {
rgb: { r: 255, g: 0, b: 0, a: 1 },
hsv: { h: 0, s: 1, v: 1, a: 1 },
}

export default exports

Choose a reason for hiding this comment

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

I was just browsing the latest release notes and inspecting the changed code and got curious about this as I couldn't find any spec about export default exports. It seems that this is some kind of Babel magic or a coincidence that Babel-generated code just exports a common-js implicit module.exports variable as the default export.

Please see the example and the generated code on the Babel REPL:
https://babeljs.io/repl#?browsers=&build=&builtIns=false&spec=false&loose=false&code_lz=KYDwDg9gTgLgBAYwgOwM7xHAvHArAbgChDRJZEV04BPbOANiMIHpm4BVZJAW2-GXgwAFgEtUcAG4BDADYiAJhXnA4MCHFTAVwlQHVoMxUhkypYTahZskaeKWgxxOAEQRuAc2fF75ZQDMpAFcZO3AHVCA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=es2015%2Creact%2Cstage-2&prettier=false&targets=&version=7.7.7&externalPlugins=

As the exports is not a reserved keyword, another export can be named exports to make this scheme to fail horribly exporting that binding, not "all the named exports" as intended by the "accidental syntax".

Please see the generated code: https://babeljs.io/repl#?browsers=&build=&builtIns=false&spec=false&loose=false&code_lz=KYDwDg9gTgLgBAYwgOwM7xHAvHArAbgChDRJZEV04BPbOANiJPGniTXlNdToCIIAtgHNexLuQAmwAGYBDAK4AbTi1iogA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=es2015%2Creact%2Cstage-2&prettier=false&targets=&version=7.7.7&externalPlugins=

@casesandberg - I think an explicit default export of all the named exports is way better as it does not rely on Babel quirks and it is a valid piece of ES code. Are PRs welcome?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Good catch! We are working on the next major release right now which is fully ES6, so it will not have these problems going forward. I appreciate your thoroughness, however!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export helpers?
2 participants