-
-
Notifications
You must be signed in to change notification settings - Fork 300
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
Check for import declaration type when getting default values, resolves #63 #99
Check for import declaration type when getting default values, resolves #63 #99
Conversation
+1: Code looks good. I've been including a similar handler manually in my application and would love to see Nathan's fix made standard. |
yeah, this looks good to me. I was wondering if it makes sense to include some additional information about the origin of the value (e.g. that it is the default import of the |
@fkling We can definitely provide some more information. We know whether it was a default or a named import, and we know the require path. Are you looking to provide information from the imported module itself? Or are you looking for something more specific about the import statement, ie: |
No. This has come up a few times and maybe we are able to resolve and inspect dependencies at some point, but I was only thinking about the import statements itself. In particular, if someone generates the docs, I can imagine they might want to link the source of the module or some other part of the page that provides more detailed information about |
We can provide some additional information in the returned object. Let me know exactly what you'd like to see, and I'll fix it up. |
@fkling any way we can get this merged for now? possibly add more info about the module later? It is currently breaking our doc build. |
@levithomason, sure! I will try to release a new version today or tomorrow. |
Super fast, thanks much! |
A common pattern in libraries is to set a default prop value as an imported component, for eg. a transition component for a dialog.
#63 has an example + a workaround (not the most elegant however, involves using a functional component to return the default component).
Right now,
react-docgen
throws an error on components implementing this pattern asImportDefaultDeclaration
is not a printable type.This PR adds a conditional after the
resolveToValue(path)
call ingetDefaultValue(path)
to check if the node is an import declaration. If so, it returns the.name
property of the original node (so the function/component name).