Skip to content

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

Merged
merged 2 commits into from
May 3, 2017
Merged

Support for create-react-class package #179

merged 2 commits into from
May 3, 2017

Conversation

wcjordan
Copy link
Contributor

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!

@fkling
Copy link
Member

fkling commented Apr 25, 2017

I just restarted the CI build. I failed with a call stack size error, but I don't see why it would...

@wcjordan
Copy link
Contributor Author

Weird. I'm able to reproduce locally though, so I can dig in.

@wcjordan
Copy link
Contributor Author

I believe the issue is that this is very promiscuous

if (!match(path.node, {type: 'CallExpression'})) {
  return false;
}
var module = resolveToModule(path.get('callee', 'object'));

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?

Copy link
Member

@fkling fkling left a 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!

if (!match(path.node, {type: 'CallExpression'})) {
return false;
}
var module = resolveToModule(path.get('callee', 'object'));
Copy link
Member

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.

@wcjordan
Copy link
Contributor Author

Your tip worked like a charm. Thanks!
Also I've added tests for existing and new functionality as well as a new snapshot.
I've also verified it works for fixed-data-table-2's usage.

I'm feeling much better about things now. Let me know if you have any additional suggestions.

@fkling fkling merged commit 6e8e489 into reactjs:master May 3, 2017
fkling pushed a commit that referenced this pull request May 3, 2017
* Support for create-react-class package

* Support for create-react-class package (take 2)
@fkling
Copy link
Member

fkling commented May 3, 2017

Published as v2.15.0 and v3.0.0-beta4. Thank you!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants