Skip to content
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

Error when component is declared before instantiated #58

Closed
abejfehr opened this issue Feb 21, 2016 · 3 comments
Closed

Error when component is declared before instantiated #58

abejfehr opened this issue Feb 21, 2016 · 3 comments
Labels
Milestone

Comments

@abejfehr
Copy link

Our components are written in CJSX, which is compiled to CoffeeScript and then straight to JS. When running react-docgen on the resultant files, I receive the ERROR_MISSING_DEFINITION error. I realize now that this because somewhere during the conversion process, my JS ends up looking like this:

var Component, React;

React = require('react');


/**
 * The is a component to test the document generation
 */

Component = React.createClass({
  displayName: 'Component',
  propTypes: {

...

Since Component = React.createClass({ isn't preceded by var, this documentation generator refuses to see the definition. This is really annoying.

@fkling fkling added the bug label Feb 23, 2016
@fkling
Copy link
Member

fkling commented Feb 23, 2016

Mmh, I see. I guess the issue is with how we resolve the identifiers to values. I guess we should be able to detect that there is only a single assignment to the variable (in the top level scope) (React and Component) and use that value then.

@abejfehr
Copy link
Author

Forgive my potential ignorance, but would I be able to write a custom resolver that would (forgive the pun) resolve this issue?

@fkling
Copy link
Member

fkling commented Mar 2, 2016

Well, if this is the only exported component, you shouldn't have to write your own resolver, we just need to fix the default one :)

As a workaround, if this is the only React component in the file anyway, you can use the findAllComponentDefinitions resolver:

react-docgen --resolver findAllComponentDefinitions src/

@fkling fkling added this to the v3 milestone Sep 27, 2016
@fkling fkling closed this as completed in 1f3cac2 Sep 28, 2016
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants