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

Support multiple exports #57

Open
samcooke98 opened this issue Apr 4, 2019 · 2 comments
Open

Support multiple exports #57

samcooke98 opened this issue Apr 4, 2019 · 2 comments

Comments

@samcooke98
Copy link

Hi there,

I was just wondering if you'd consider supporting files that export multiple components?

I noticed in here that you just take the first component: https://github.com/atlassian/extract-react-types/blob/master/packages/extract-react-types/src/index.js#L132

I'm happy to submit a PR for this, just wanted to see if that would be something you'd be open to supporting?

Thanks

@samcooke98 samcooke98 changed the title Support multiple export Support multiple exports Apr 4, 2019
@Noviny
Copy link
Contributor

Noviny commented Apr 4, 2019

Hey Sam! Thanks for raising this issue! It's a good idea, with some design constraints/history worth knowing about before diving in to it.

We actually used to do this (on the extract-react-types side anyway, pretty-prop-types (the rendering engine) always took the first component which is not ideal).

Basically it found everything in your file that was a React.Component.

We switched this when we switched to also analysing functional components, which switched us to analysing export instead of just found components. By only looking at default, we can make an assumption that the export is a component (functional or otherwise), and analyse them like that. In fact, our logic to detect a functional component is just

if (
path.isFunctionExpression() ||
path.isArrowFunctionExpression() ||
path.isFunctionDeclaration()
) {
let component = convertReactComponentFunction(path, context);
components.push({ name, path, component });
return;
}

:badpokerface:

Analysing multiple exports and being confident they are all components probably means implementing real logic here that determines whether a function is a function component or not.

(Though we want to do that anyway, as extract-react-types does enough now we're thinking about pointing it at function and object signatures, as it theoretically does these anyway)

Uh, hope that helps answer your question!

The easy answer is yes, qualified by the above.

@Noviny
Copy link
Contributor

Noviny commented Apr 4, 2019

ps. If you want to just use multiple exports now, you can via this exported function that we have failed to document:

module.exports.findExportedComponents = (
programPath /*: any */,
typeSystem /*: 'flow' | 'typescript' */,
filename /*:? string */,
resolveOptions /*:? Object */
) => {
return findExportedComponents(
programPath,
'all',
getContext(typeSystem, filename, resolveOptions)
);
};

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

No branches or pull requests

2 participants