react-docgen icon indicating copy to clipboard operation
react-docgen copied to clipboard

Brace-only imports with elided semicolons breaks component description

Open matterweave opened this issue 5 years ago • 1 comments

I have this happening in a local project, but I was also able to reproduce it with a simple example in the playground. If you go to http://reactcommunity.org/react-docgen/ and paste in the following, the description shows up as empty:

import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Thing } from 'somewhere'

/**
 * Sample doc for component.
 */
const Functional = (props) => {
  return (<div>{props.foo}</div>)
}

Functional.propTypes = {
  /**
   * Description of prop "foo".
   */
  foo: PropTypes.number
}

export default Functional

It only affects the first documentation comment, and then the parser flips back to a working state for whatever reason and properly parses the prop types.

Adding a semicolon, or rearranging the imports so a non-specific import is last in the order fixes it and the component description is parsed properly again.

matterweave avatar Jan 22 '20 00:01 matterweave

Is this still a problem? I just tried on the website and it seems to be working. It might have to do with the version of @babel/parser you are using, try updating it to the latest version.

danez avatar Feb 06 '20 23:02 danez