-
-
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
Refactor for flow intersection and union Props #97
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,50 @@ export default (path: NodePath): ?NodePath => { | |
if (typePath && types.GenericTypeAnnotation.check(typePath.node)) { | ||
typePath = resolveToValue(typePath.get('id')); | ||
if ( | ||
!typePath || | ||
!typePath || | ||
types.Identifier.check(typePath.node) || | ||
isUnreachableFlowType(typePath) | ||
) { | ||
return; | ||
} | ||
|
||
typePath = typePath.get('right'); | ||
} | ||
|
||
return typePath; | ||
} | ||
|
||
export function applyToFlowTypeProperties( | ||
path: NodePath, | ||
callback: (propertyPath: NodePath) => void | ||
) { | ||
if (path.node.properties) { | ||
path.get('properties').each( | ||
propertyPath => callback(propertyPath) | ||
); | ||
} else if (path.node.type == 'IntersectionTypeAnnotation') { | ||
path.get('types').each( | ||
typesPath => applyToFlowTypeProperties(typesPath, callback) | ||
); | ||
} else if (path.node.type == 'UnionTypeAnnotation') { | ||
// The react-docgen output format does not currently allow | ||
// for the expression of union types | ||
throw new TypeError("react-docgen doesn't support Props of union types"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree now, that generating props from union types is more tricky and a bad idea like it was before, but imho it would be better to just ignore the type instead of throwing an exception. People should not be forced to restructure their code just to get the docs working. If I think of my companies huge codebase, this might break the complete docs even if it's just one component that has an union type. |
||
} else { | ||
let typePath = resolveGenericTypeAnnotation(path); | ||
if (typePath) { | ||
applyToFlowTypeProperties(typePath, callback); | ||
} | ||
} | ||
} | ||
|
||
function resolveGenericTypeAnnotation(path: NodePath): ?NodePath { | ||
// If the node doesn't have types or properties, try to get the type. | ||
let typePath: ?NodePath; | ||
if (path && types.GenericTypeAnnotation.check(path.node)) { | ||
typePath = resolveToValue(path.get('id')); | ||
if ( | ||
!typePath || | ||
types.Identifier.check(typePath.node) || | ||
isUnreachableFlowType(typePath) | ||
) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think most of this imports above are unused.