storybookjs/babel-plugin-react-docgen

Use the React stateless class detector used in react-docgen

arunoda opened this issue · 5 comments

React Docgen has it's own way to detecting React stateless classes. So it's better to use that.
It's located in: https://github.com/reactjs/react-docgen/blob/master/src/utils/isStatelessComponent.js

We can get it directly with:

import isStatelessComponent from 'react-docgen/dist/utils/isStatelessComponent'

@madushan1000 check this out.
I also did #15 to fix this issue: storybookjs/storybook#558

I tried using it before. But react-docgen uses recast as the AST walker. And recast doesn't seem to support babel6 ASTs(react-docgen specifically uses babylon5, the parser form babel5). So we can't use those functions.
But it looks like there are some options(https://babeljs.io/blog/2016/09/28/6.16.0) we can pass to the parser so it generates recast compatible ASTs. I'll try it today.

So, using babel parser and generator options we can use recast for both instead of babylon in bable6. But I think it's overkill for just one plugin.

Okay. Let's leave it like this for now.

for context, docgen moved over to babylon but their isStatelessComponent isn't on parity with ours so there's no point moving over.