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

react-docgen

Package Overview
Dependencies
Maintainers
1
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.16.0 to 2.17.0

57

dist/handlers/componentMethodsHandler.js

@@ -30,31 +30,29 @@ 'use strict';

var types = _recast2.default.types.namedTypes; /*
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
var types = _recast2.default.types.namedTypes;
function getMethodsDoc(methodPaths) {
var methods = [];
/**
* The following values/constructs are considered methods:
*
* - Method declarations in classes (except "constructor" and React lifecycle
* methods
* - Public class fields in classes whose value are a functions
* - Object properties whose values are functions
*/
/*
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
methodPaths.forEach(function (methodPath) {
if ((0, _isReactComponentMethod2.default)(methodPath)) {
return;
}
function isMethod(path) {
var isProbablyMethod = types.MethodDefinition.check(path.node) && path.node.kind !== 'constructor' || types.ClassProperty.check(path.node) && types.Function.check(path.get('value').node) || types.Property.check(path.node) && types.Function.check(path.get('value').node);
methods.push((0, _getMethodDocumentation2.default)(methodPath));
});
return methods;
return isProbablyMethod && !(0, _isReactComponentMethod2.default)(path);
}
function isFunctionExpression(path) {
return types.FunctionExpression.check(path.get('value').node);
}
/**

@@ -68,7 +66,5 @@ * Extract all flow types for the methods of a react component. Doesn't

if ((0, _isReactComponentClass2.default)(path)) {
methodPaths = path.get('body', 'body').filter(function (p) {
return types.MethodDefinition.check(p.node) && p.node.kind !== 'constructor';
});
methodPaths = path.get('body', 'body').filter(isMethod);
} else if (types.ObjectExpression.check(path.node)) {
methodPaths = path.get('properties').filter(isFunctionExpression);
methodPaths = path.get('properties').filter(isMethod);

@@ -79,3 +75,3 @@ // Add the statics object properties.

statics.get('properties').each(function (p) {
if (isFunctionExpression(p)) {
if (isMethod(p)) {
p.node.static = true;

@@ -88,4 +84,3 @@ methodPaths.push(p);

var methods = getMethodsDoc(methodPaths);
documentation.set('methods', methods);
documentation.set('methods', methodPaths.map(_getMethodDocumentation2.default));
}

@@ -117,4 +117,3 @@ 'use strict';

var propDescriptor = documentation.getPropDescriptor((0, _getPropertyName2.default)(propertyPath));
var value = isStatelessComponent ? propertyPath.get('value', 'right') : propertyPath.get('value');
var defaultValue = getDefaultValue(value, isStatelessComponent);
var defaultValue = getDefaultValue(isStatelessComponent ? propertyPath.get('value', 'right') : propertyPath.get('value'));
if (defaultValue) {

@@ -121,0 +120,0 @@ propDescriptor.defaultValue = defaultValue;

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

case types.ObjectPattern.name:
case types.ArrayPattern.name:
return (0, _printValue2.default)(parameterPath);

@@ -39,0 +40,0 @@ case types.RestElement.name:

@@ -42,3 +42,4 @@ 'use strict';

function isRenderMethod(node) {
return types.MethodDefinition.check(node) && !node.computed && !node.static && (node.kind === '' || node.kind === 'method') && node.key.name === 'render';
var isProperty = node.type === 'ClassProperty';
return (types.MethodDefinition.check(node) || isProperty) && !node.computed && !node.static && (node.kind === '' || node.kind === 'method' || isProperty) && node.key.name === 'render';
}

@@ -45,0 +46,0 @@

@@ -6,2 +6,7 @@ 'use strict';

});
var _getIterator2 = require('babel-runtime/core-js/get-iterator');
var _getIterator3 = _interopRequireDefault(_getIterator2);
exports.default = resolveToValue;

@@ -121,8 +126,35 @@

if (types.ObjectExpression.check(resolved.node)) {
var memberParts = (0, _expressionTo.Array)(path).slice(1);
var init = memberParts.reduce(function (propertyPath, propertyName) {
propertyPath = resolveToValue(propertyPath);
return types.ObjectExpression.check(propertyPath.node) ? (0, _getPropertyValuePath2.default)(propertyPath, propertyName) : null;
}, resolved);
return init ? resolveToValue(init) : path;
var propertyPath = resolved;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = (0, _getIterator3.default)((0, _expressionTo.Array)(path).slice(1)), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var propertyName = _step.value;
if (propertyPath && types.ObjectExpression.check(propertyPath.node)) {
propertyPath = (0, _getPropertyValuePath2.default)(propertyPath, propertyName);
}
if (!propertyPath) {
return path;
}
propertyPath = resolveToValue(propertyPath);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return propertyPath;
}

@@ -129,0 +161,0 @@ } else if (types.ImportDefaultSpecifier.check(node) || types.ImportNamespaceSpecifier.check(node) || types.ImportSpecifier.check(node)) {

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

@@ -37,3 +37,3 @@ "repository": {

"node-dir": "^0.1.10",
"recast": "^0.11.5"
"recast": "^0.12.6"
},

@@ -43,3 +43,3 @@ "devDependencies": {

"babel-eslint": "^7.0.0",
"babel-jest": "^18.0.0",
"babel-jest": "^20.0.3",
"babel-plugin-transform-object-rest-spread": "^6.23.0",

@@ -50,5 +50,5 @@ "babel-plugin-transform-runtime": "^6.9.0",

"cross-spawn": "^5.0.0",
"eslint": "^3.2.2",
"flow-bin": "^0.39.0",
"jest": "^18.1.0",
"eslint": "^4.3.0",
"flow-bin": "^0.50.0",
"jest": "^20.0.4",
"rimraf": "^2.3.2",

@@ -59,3 +59,3 @@ "temp": "^0.8.1"

"setupTestFrameworkScriptFile": "<rootDir>/tests/setupTestFramework.js",
"testPathDirs": [
"roots": [
"bin",

@@ -62,0 +62,0 @@ "src"

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

[recast]: https://github.com/benjamn/recast
[babylon]: https://github.com/babel/babel/tree/master/packages/babylon
[babylon]: https://github.com/babel/babylon
[classes]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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