Comments (5)
I tried to do it
What exactly did you try?
i had problem with npm test
I fixed the test setup in 546635c .
from react-docgen.
Closing this, since I haven't heard back. I'm also not sure if we can do much here, since, in general, the shape of transpiled code is unknown and there may not be enough information to find the information we we want.
from react-docgen.
Hello!
I have also tried to gather documentation for sources after Babel.
Currently, there is now a problem with _interopRequireDefault
function:
Given the following code
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var React = _interopDefault(require('react'));
function MyComponent(_ref) {
var className = _ref.className,
children = _ref.children,
style = _ref.style;
return React.createElement(
'button',
{ className: className, style: style },
children
);
}
module.exports = MyComponent;
The problem here is that React
identifier is recognized as a result of unknown _interopDefault
function. I think it makes sense to check the arguments of the call, whether there is a require
or not.
When I added there also a check for arguments, it worked fine.
What do you think about fixing this?
from react-docgen.
@just-boris, why do you run react-docgen on compiled code? In general I don't think it makes sense to try to fix this since Babel removes a lot of the syntax that react-docgen uses to extract information. Just think about what classes are compiled to:
class Foo extends React.Component {
propTypes = {
bar: React.PropTypes.string,
};
}
becomes
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Foo = function (_React$Component) {
_inherits(Foo, _React$Component);
function Foo() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, Foo);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Foo.__proto__ || Object.getPrototypeOf(Foo)).call.apply(_ref, [this].concat(args))), _this), _this.propTypes = {
bar: React.PropTypes.string
}, _temp), _possibleConstructorReturn(_this, _ret);
}
return Foo;
}(React.Component);
I'd think this becomes impossible to reliably extract information from.
from react-docgen.
Well, of course, if I could run Docgen on top of source code, I did it...
In my case, the problem is that build process for files is a bit complex. I am trying to build documentation using React-styleguidist, it requires me to use Webpack, but the project is built with Rollup, so I have to either, maintain the second version of configuration with Webpack loaders, or just generate documentation based on built files.
Also, to define propTypes, you need to add as static
property, and then Babel will write it like
var Foo = function (_React$Component) {
_inherits(Foo, _React$Component);
function Foo() {
_classCallCheck(this, Foo);
return _possibleConstructorReturn(this, (Foo.__proto__ || Object.getPrototypeOf(Foo)).apply(this, arguments));
}
return Foo;
}(React.Component);
Foo.propTypes = {
bar: React.PropTypes.string
};
Which is recongizable by React-docgen right now.
I have already built a styleguide with modified version of React-docgen, and the only problem, that I have found was about unrecognized React require
.
from react-docgen.
Related Issues (20)
- react-docgen cannot extract comments with hermes-parser HOT 3
- Fow indexed access types results in `unknow` HOT 2
- useCallback + useImperativeHandle methods
- Expose more TypeScript types HOT 1
- react-docgen v6.0.0 & older changelogs HOT 2
- Property accessors as template literals causes errors with react-docgen v7 HOT 4
- Better TS enum support
- TS forwardRef support HOT 1
- With Typescript Omit Union types get lost
- With forwardRef Union types get lost HOT 1
- Internal server error: Argument must be Identifier, Literal, QualifiedTypeIdentifier or TSQualifiedName. Received 'TemplateLiteral' HOT 2
- Fails when a namespaced export is used HOT 1
- When postcss modules are present, in some scenarios react-docgen tries to parse css files HOT 2
- Typescript: Component props not parsed with 'call signature' type
- Typescript: Component declaration reference is not recognized by parser
- @defaultValue is not parsed from interface
- "Attempted to resolveName for an unsupported path" error HOT 2
- Decorators must be placed *after* the 'export' keyword. Remove the 'decoratorsBeforeExport: false' option to use the '@decorator export class {}' syntax.
- Using `Readonly<T>` utility type results in losing pieces of `T`'s information
- TypeScript: Missing Union Elements of Indexed Access Type
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-docgen.