-
Notifications
You must be signed in to change notification settings - Fork 257
feat: extract default props from destructuring #200
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
feat: extract default props from destructuring #200
Conversation
"chai": "^4.1.2", | ||
"husky": "^0.14.3", | ||
"lint-staged": "^7.2.0", | ||
"lint-staged": "^7.3.0", |
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.
upped version because current version was exiting with Error: Cannot find any-observable implementation nor global.Observable.
check('StatelessWithDefaultProps', expectation); | ||
}); | ||
|
||
it('should parse referenced props', () => { |
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.
Deleted these 2 tests (should parse referenced props
and supports spread props
) because this use cases are not actually supported and default props are not properly generated. These tests were not failing on master because of incorrect check inside test code itself: see https://github.com/styleguidist/react-docgen-typescript/pull/200/files#diff-a063097dc09ae77820847611faefb99b
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.
Thanks for explanation.
} | ||
|
||
const statement = possibleStatements[0]; | ||
return possibleStatements.reduce((res, statement) => { |
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.
merging multiple definitions in case of defaultProps are used together with desctructuring
The version including this code has been published to npm as v1.13.0. |
Thank you for adding this feature - very useful! Something I notice is that if you destructure props inside the function rather than in the declaration, default props are not picked up. Would it make sense to support this case?
|
@rmunch It is certainly possible to support this case, but there's no need in it right now on my current project. If you would try to add it yourself, I think you need to find an assignment statement with |
Fixes #154
Added support for extracting default prop values from object desctructuring inside functional components.