-
-
Notifications
You must be signed in to change notification settings - Fork 303
Support for create-react-class package #179
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
Conversation
I just restarted the CI build. I failed with a call stack size error, but I don't see why it would... |
Weird. I'm able to reproduce locally though, so I can dig in. |
I believe the issue is that this is very promiscuous
One heuristic I could take would be to assume the method will be named createReactClass e.g. import createReactClass from 'create-react-class'; or const createReactClass = require('create-react-class');. Another alternative might be to make a lighter weight version of resolveToModule which doesn't follow MemberExpressions or VariableDeclarators e.g. assume we're importing directly into the variable as which we use createReactClass. Thoughts? Also I'd like to write some tests for these cases. Would it be best to imitate something like isReactComponentClass-test.js? |
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.
Also I'd like to write some tests for these cases. Would it be best to imitate something like isReactComponentClass-test.js?
Yep, that's a good idea (I didn't realize there was no unit test for that module)! Adding a component to https://github.com/reactjs/react-docgen/tree/master/src/__tests__/fixtures for the snapshot test would also be good.
Thank you for working on this!
src/utils/isReactCreateClassCall.js
Outdated
if (!match(path.node, {type: 'CallExpression'})) { | ||
return false; | ||
} | ||
var module = resolveToModule(path.get('callee', 'object')); |
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.
This might actually be the culprit. The value of callee
for the CallExpression
is Identifier
, which doesn't have an object
field: http://astexplorer.net/#/gist/2830b1b852ac298dab2f18802133afdf/ec06e05ba93e93903bb7c85a1bd6a12622d41918 .
I think you can do resolveToModule(path)
here, that should solve the issue.
Your tip worked like a charm. Thanks! I'm feeling much better about things now. Let me know if you have any additional suggestions. |
* Support for create-react-class package * Support for create-react-class package (take 2)
Published as v2.15.0 and v3.0.0-beta4. Thank you! |
Fixes #176, adding support for the new create-react-class package.
I'm not familiar with recast (but have dabbled with estraverse), so any tips or suggestions are appreciated. Thanks!