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.1.2 to 2.2.0

dist/utils/isRequiredPropType.js

33

dist/handlers/componentDocblockHandler.js

@@ -30,2 +30,7 @@ /*

function isClassDefinition(nodePath) {
var node = nodePath.node;
return types.ClassDeclaration.check(node) || types.ClassExpression.check(node);
}
/**

@@ -38,25 +43,33 @@ * Finds the nearest block comment before the component definition.

// Find parent statement (e.g. var Component = React.createClass(<path>);)
while (path && !types.Statement.check(path.node)) {
path = path.parent;
var searchPath = path;
while (searchPath && !types.Statement.check(searchPath.node)) {
searchPath = searchPath.parent;
}
if (path) {
if (searchPath) {
// Class declarations are statements but can be part of default
// export declarations
if (types.ClassDeclaration.check(path.node) && types.ExportDefaultDeclaration.check(path.parentPath.node)) {
path = path.parentPath;
if (types.ClassDeclaration.check(searchPath.node) && types.ExportDefaultDeclaration.check(searchPath.parentPath.node)) {
searchPath = searchPath.parentPath;
}
// If the parent is an export statement, we have to traverse one more up
if (types.ExportNamedDeclaration.check(path.parentPath.node)) {
path = path.parentPath;
if (types.ExportNamedDeclaration.check(searchPath.parentPath.node)) {
searchPath = searchPath.parentPath;
}
description = (0, _utilsDocblock.getDocblock)(path);
description = (0, _utilsDocblock.getDocblock)(searchPath);
}
if (description == null && isClassDefinition(path)) {
// If we have a class declaration or expression, then the comment might be
// attached to the first decorator instead.
if (path.node.decorators && path.node.decorators.length > 0) {
description = (0, _utilsDocblock.getDocblock)(path.get('decorators', 0));
}
}
if (description == null) {
// If this is the first statement in the module body, the comment is attached
// to the program node
var programPath = path;
var programPath = searchPath;
while (programPath && !types.Program.check(programPath.node)) {
programPath = programPath.parent;
}
if (programPath.get('body', 0) === path) {
if (programPath.get('body', 0) === searchPath) {
description = (0, _utilsDocblock.getDocblock)(programPath);

@@ -63,0 +76,0 @@ }

@@ -22,6 +22,2 @@ /*

var _utilsGetMembers = require('../utils/getMembers');
var _utilsGetMembers2 = _interopRequireDefault(_utilsGetMembers);
var _utilsGetPropType = require('../utils/getPropType');

@@ -43,2 +39,6 @@

var _utilsIsRequiredPropType = require('../utils/isRequiredPropType');
var _utilsIsRequiredPropType2 = _interopRequireDefault(_utilsIsRequiredPropType);
var _utilsPrintValue = require('../utils/printValue');

@@ -70,11 +70,2 @@

/**
* Returns true of the prop is required, according to its type defintion
*/
function isRequired(path) {
return (0, _utilsGetMembers2['default'])(path).some(function (member) {
return !member.computed && member.path.node.name === 'isRequired' || member.computed && member.path.node.value === 'isRequired';
});
}
function amendPropTypes(documentation, path) {

@@ -90,3 +81,3 @@ path.get('properties').each(function (propertyPath) {

propDescriptor.type = type;
propDescriptor.required = type.name !== 'custom' && isRequired(valuePath);
propDescriptor.required = type.name !== 'custom' && (0, _utilsIsRequiredPropType2['default'])(valuePath);
}

@@ -93,0 +84,0 @@ break;

@@ -43,10 +43,16 @@ /*

function getDocblock(path) {
var comments = [];
if (path.node.comments) {
var comments = path.node.comments.filter(function (comment) {
comments = path.node.comments.filter(function (comment) {
return comment.leading && comment.type === 'CommentBlock' && DOCBLOCK_HEADER.test(comment.value);
});
if (comments.length > 0) {
return parseDocblock(comments[comments.length - 1].value);
}
} else if (path.node.leadingComments) {
comments = path.node.leadingComments.filter(function (comment) {
return comment.type === 'CommentBlock' && DOCBLOCK_HEADER.test(comment.value);
});
}
if (comments.length > 0) {
return parseDocblock(comments[comments.length - 1].value);
}
return null;

@@ -53,0 +59,0 @@ }

@@ -48,2 +48,4 @@ /*

function getMembers(path) {
var includeRoot = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
var result = [];

@@ -71,2 +73,9 @@ var argumentsPath = null;

}
if (includeRoot && result.length > 0) {
result.push({
path: path,
computed: false,
argumentsPath: argumentsPath
});
}
return result.reverse();

@@ -73,0 +82,0 @@ }

@@ -34,2 +34,6 @@ /*

var _utilsIsRequiredPropType = require('../utils/isRequiredPropType');
var _utilsIsRequiredPropType2 = _interopRequireDefault(_utilsIsRequiredPropType);
var _printValue = require('./printValue');

@@ -102,3 +106,3 @@

argumentPath.get('properties').each(function (propertyPath) {
var descriptor = getPropType(propertyPath.get('value'), true);
var descriptor = getPropType(propertyPath.get('value'));
var docs = (0, _utilsDocblock.getDocblock)(propertyPath);

@@ -108,2 +112,3 @@ if (docs) {

}
descriptor.required = (0, _utilsIsRequiredPropType2['default'])(propertyPath.get('value'));
type.value[(0, _getPropertyName2['default'])(propertyPath)] = descriptor;

@@ -154,3 +159,3 @@ });

var descriptor;
(0, _getMembers2['default'])(path).some(function (member) {
(0, _getMembers2['default'])(path, true).some(function (member) {
var node = member.path.node;

@@ -157,0 +162,0 @@ var name;

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

@@ -27,8 +27,8 @@ "repository": {

"dependencies": {
"async": "^0.9.0",
"babel-runtime": "^5.7.0",
"async": "^1.4.2",
"babel-runtime": "~5.8.25",
"babylon": "~5.8.3",
"node-dir": "^0.1.6",
"node-dir": "^0.1.10",
"nomnom": "^1.8.1",
"recast": "^0.10.31"
"recast": "^0.10.33"
},

@@ -38,4 +38,3 @@ "devDependencies": {

"babel-jest": "^5.3.0",
"es6-promise": "^2.0.1",
"jest-cli": "^0.4.0",
"jest-cli": "^0.5.8",
"rimraf": "^2.3.2",

@@ -42,0 +41,0 @@ "temp": "^0.8.1"

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