Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

react-docgen

Package Overview
Dependencies
Maintainers
2
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-docgen - npm Package Compare versions

Comparing version 2.19.0 to 2.20.0

54

dist/utils/getFlowType.js

@@ -33,6 +33,4 @@ 'use strict';

var _isUnreachableFlowType = require('../utils/isUnreachableFlowType');
var _resolveObjectKeysToArray = require('../utils/resolveObjectKeysToArray');
var _isUnreachableFlowType2 = _interopRequireDefault(_isUnreachableFlowType);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -79,3 +77,4 @@

IntersectionTypeAnnotation: handleIntersectionTypeAnnotation,
TupleTypeAnnotation: handleTupleTypeAnnotation
TupleTypeAnnotation: handleTupleTypeAnnotation,
TypeofTypeAnnotation: handleTypeofTypeAnnotation
};

@@ -91,5 +90,37 @@

function handleKeysHelper(path) {
var value = path.get('typeParameters', 'params', 0);
if (types.TypeofTypeAnnotation.check(value.node)) {
value = value.get('argument', 'id');
} else {
value = value.get('id');
}
var resolvedPath = (0, _resolveToValue2.default)(value);
if (resolvedPath && types.ObjectExpression.check(resolvedPath.node)) {
var keys = (0, _resolveObjectKeysToArray.resolveObjectExpressionToNameArray)(resolvedPath, true);
if (keys) {
return {
name: 'union',
raw: (0, _printValue2.default)(path),
elements: keys.map(function (value) {
return { name: 'literal', value: value };
})
};
}
}
}
function handleGenericTypeAnnotation(path) {
var type = { name: path.node.id.name };
if (path.node.id.name === '$Keys' && path.node.typeParameters) {
return handleKeysHelper(path);
}
var type = void 0;
if (types.QualifiedTypeIdentifier.check(path.node.id)) {
type = handleQualifiedTypeIdentifier(path.get('id'));
} else {
type = { name: path.node.id.name };
}
if (path.node.typeParameters) {

@@ -106,4 +137,3 @@ var params = path.get('typeParameters').get('params');

var resolvedPath = (0, _resolveToValue2.default)(path.get('id'));
if (!(0, _isUnreachableFlowType2.default)(resolvedPath)) {
if (resolvedPath && resolvedPath.node.right) {
type = getFlowType(resolvedPath.get('right'));

@@ -210,2 +240,12 @@ }

function handleTypeofTypeAnnotation(path) {
return getFlowType(path.get('argument'));
}
function handleQualifiedTypeIdentifier(path) {
if (path.node.qualification.name !== 'React') return;
return { name: 'React' + path.node.id.name, raw: (0, _printValue2.default)(path) };
}
/**

@@ -212,0 +252,0 @@ * Tries to identify the flow type by inspecting the path for known

2

dist/utils/getFlowTypeFromReactComponent.js

@@ -120,3 +120,3 @@ 'use strict';

typePath = (0, _resolveToValue2.default)(path.get('id'));
if (!typePath || types.Identifier.check(typePath.node) || (0, _isUnreachableFlowType2.default)(typePath)) {
if ((0, _isUnreachableFlowType2.default)(typePath)) {
return;

@@ -123,0 +123,0 @@ }

@@ -11,2 +11,3 @@ 'use strict';

exports.resolveObjectExpressionToNameArray = resolveObjectExpressionToNameArray;
exports.default = resolveObjectKeysToArray;

@@ -48,2 +49,4 @@

function resolveObjectExpressionToNameArray(objectExpression) {
var raw = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (types.ObjectExpression.check(objectExpression.value) && objectExpression.value.properties.every(function (prop) {

@@ -60,3 +63,3 @@ return types.Property.check(prop) && (types.Identifier.check(prop.key) && !prop.computed || types.Literal.check(prop.key)) || types.SpreadProperty.check(prop);

// Key is either Identifier or Literal
var name = prop.key.name || prop.key.value;
var name = prop.key.name || (raw ? prop.key.raw : prop.key.value);

@@ -63,0 +66,0 @@ values.push(name);

{
"name": "react-docgen",
"version": "2.19.0",
"version": "2.20.0",
"description": "A CLI and toolkit to extract information from React components for documentation generation.",

@@ -20,10 +20,9 @@ "repository": {

"scripts": {
"check": "npm run lint && npm run flow && npm test",
"flow": "flow",
"lint": "eslint src/",
"watch": "babel src/ --out-dir dist/ --watch",
"build": "rimraf dist/ && babel src/ --out-dir dist/ --ignore __tests__,__mocks__",
"prepublish": "npm run build",
"preversion": "npm run lint",
"test": "jest"
"lint": "eslint src/ bin/",
"prepublish": "yarn run build",
"preversion": "yarn run lint",
"test": "jest",
"test:ci": "yarn lint && yarn flow && yarn test --runInBand",
"watch": "yarn build --watch"
},

@@ -46,15 +45,16 @@ "keywords": [

"devDependencies": {
"babel-cli": "^6.9.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-eslint": "^7.0.0",
"babel-jest": "^20.0.3",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-plugin-transform-runtime": "^6.9.0",
"babel-preset-env": "^1.1.8",
"babel-jest": "^21.2.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.1",
"babel-preset-flow": "^6.23.0",
"cross-spawn": "^5.0.0",
"eslint": "^4.3.0",
"flow-bin": "^0.53.1",
"jest": "^20.0.4",
"jest-diff": "^20.0.3",
"jest-matcher-utils": "^20.0.3",
"flow-bin": "^0.59.0",
"jest": "^21.2.1",
"jest-diff": "^21.2.1",
"jest-matcher-utils": "^21.2.1",
"rimraf": "^2.3.2",

@@ -61,0 +61,0 @@ "temp": "^0.8.1"

@@ -122,3 +122,4 @@ # react-docgen [![Build Status](https://travis-ci.org/reactjs/react-docgen.svg?branch=master)](https://travis-ci.org/reactjs/react-docgen)

```js
var React = require('react');
import React, { Component } from 'react';
import PropTypes from 'prop-types';

@@ -128,33 +129,31 @@ /**

*/
var Component = React.createClass({
propTypes: {
/**
* Description of prop "foo".
*/
foo: React.PropTypes.number,
/**
* Description of prop "bar" (a custom validation function).
*/
bar: function(props, propName, componentName) {
// ...
},
baz: React.PropTypes.oneOfType([
React.PropTypes.number,
React.PropTypes.string
]),
},
getDefaultProps: function() {
return {
foo: 42,
bar: 21
};
},
class MyComponent extends Component {
render: function() {
// ...
}
});
}
module.exports = Component;
MyComponent.propTypes = {
/**
* Description of prop "foo".
*/
foo: PropTypes.number,
/**
* Description of prop "bar" (a custom validation function).
*/
bar: function(props, propName, componentName) {
// ...
},
baz: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string
]),
};
MyComponent.defaultProps = {
foo: 42,
bar: 21
};
export default Component;
```

@@ -161,0 +160,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc