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

react-docgen

Package Overview
Dependencies
Maintainers
3
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.20.1 to 2.21.0

92

dist/Documentation.js

@@ -50,2 +50,4 @@ "use strict";

this._props = new _map2.default();
this._context = new _map2.default();
this._childContext = new _map2.default();
this._composes = new _set2.default();

@@ -80,2 +82,20 @@ this._data = new _map2.default();

}, {
key: "getContextDescriptor",
value: function getContextDescriptor(propName) {
var propDescriptor = this._context.get(propName);
if (!propDescriptor) {
this._context.set(propName, propDescriptor = {});
}
return propDescriptor;
}
}, {
key: "getChildContextDescriptor",
value: function getChildContextDescriptor(propName) {
var propDescriptor = this._childContext.get(propName);
if (!propDescriptor) {
this._childContext.set(propName, propDescriptor = {});
}
return propDescriptor;
}
}, {
key: "toObject",

@@ -127,6 +147,6 @@ value: function toObject() {

var name = _ref4[0];
var descriptor = _ref4[1];
var propName = _ref4[0];
var propDescriptor = _ref4[1];
obj.props[name] = descriptor;
obj.props[propName] = propDescriptor;
}

@@ -149,2 +169,68 @@ } catch (err) {

if (this._context.size > 0) {
obj.context = {};
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator3 = (0, _getIterator3.default)(this._context), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var _ref5 = _step3.value;
var _ref6 = (0, _slicedToArray3.default)(_ref5, 2);
var contextName = _ref6[0];
var contextDescriptor = _ref6[1];
obj.context[contextName] = contextDescriptor;
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}
}
if (this._childContext.size > 0) {
obj.childContext = {};
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;
try {
for (var _iterator4 = (0, _getIterator3.default)(this._childContext), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var _ref7 = _step4.value;
var _ref8 = (0, _slicedToArray3.default)(_ref7, 2);
var childContextName = _ref8[0];
var childContextDescriptor = _ref8[1];
obj.childContext[childContextName] = childContextDescriptor;
}
} catch (err) {
_didIteratorError4 = true;
_iteratorError4 = err;
} finally {
try {
if (!_iteratorNormalCompletion4 && _iterator4.return) {
_iterator4.return();
}
} finally {
if (_didIteratorError4) {
throw _iteratorError4;
}
}
}
}
if (this._composes.size > 0) {

@@ -151,0 +237,0 @@ obj.composes = (0, _from2.default)(this._composes);

@@ -48,5 +48,17 @@ 'use strict';

get: function get() {
return _interopRequireDefault(_propTypeHandler).default;
return _propTypeHandler.propTypeHandler;
}
});
Object.defineProperty(exports, 'contextTypeHandler', {
enumerable: true,
get: function get() {
return _propTypeHandler.contextTypeHandler;
}
});
Object.defineProperty(exports, 'childContextTypeHandler', {
enumerable: true,
get: function get() {
return _propTypeHandler.childContextTypeHandler;
}
});

@@ -53,0 +65,0 @@ var _propTypeCompositionHandler = require('./propTypeCompositionHandler');

47

dist/handlers/propTypeHandler.js

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

});
exports.default = propTypeHandler;
exports.childContextTypeHandler = exports.contextTypeHandler = exports.propTypeHandler = undefined;

@@ -70,3 +70,3 @@ var _getPropType = require('../utils/getPropType');

function amendPropTypes(documentation, path) {
function amendPropTypes(getDescriptor, path) {
if (!types.ObjectExpression.check(path.node)) {

@@ -79,3 +79,3 @@ return;

case types.Property.name:
var propDescriptor = documentation.getPropDescriptor((0, _getPropertyName2.default)(propertyPath));
var propDescriptor = getDescriptor((0, _getPropertyName2.default)(propertyPath));
var valuePath = propertyPath.get('value');

@@ -94,3 +94,3 @@ var type = isPropTypesExpression(valuePath) ? (0, _getPropType2.default)(valuePath) : { name: 'custom', raw: (0, _printValue2.default)(valuePath) };

// normal object literal
amendPropTypes(documentation, resolvedValuePath);
amendPropTypes(getDescriptor, resolvedValuePath);
break;

@@ -103,12 +103,29 @@ }

function propTypeHandler(documentation, path) {
var propTypesPath = (0, _getMemberValuePath2.default)(path, 'propTypes');
if (!propTypesPath) {
return;
}
propTypesPath = (0, _resolveToValue2.default)(propTypesPath);
if (!propTypesPath) {
return;
}
amendPropTypes(documentation, propTypesPath);
}
function getPropTypeHandler(propName) {
return function (documentation, path) {
var propTypesPath = (0, _getMemberValuePath2.default)(path, propName);
if (!propTypesPath) {
return;
}
propTypesPath = (0, _resolveToValue2.default)(propTypesPath);
if (!propTypesPath) {
return;
}
var getDescriptor = void 0;
switch (propName) {
case 'childContextTypes':
getDescriptor = documentation.getChildContextDescriptor;
break;
case 'contextTypes':
getDescriptor = documentation.getContextDescriptor;
break;
default:
getDescriptor = documentation.getPropDescriptor;
}
amendPropTypes(getDescriptor.bind(documentation), propTypesPath);
};
}
var propTypeHandler = exports.propTypeHandler = getPropTypeHandler('propTypes');
var contextTypeHandler = exports.contextTypeHandler = getPropTypeHandler('contextTypes');
var childContextTypeHandler = exports.childContextTypeHandler = getPropTypeHandler('childContextTypes');

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

var defaultResolver = resolver.findExportedComponentDefinition;
var defaultHandlers = [handlers.propTypeHandler, handlers.propTypeCompositionHandler, handlers.propDocBlockHandler, handlers.flowTypeHandler, handlers.flowTypeDocBlockHandler, handlers.defaultPropsHandler, handlers.componentDocblockHandler, handlers.displayNameHandler, handlers.componentMethodsHandler, handlers.componentMethodsJsDocHandler];
var defaultHandlers = [handlers.propTypeHandler, handlers.contextTypeHandler, handlers.childContextTypeHandler, handlers.propTypeCompositionHandler, handlers.propDocBlockHandler, handlers.flowTypeHandler, handlers.flowTypeDocBlockHandler, handlers.defaultPropsHandler, handlers.componentDocblockHandler, handlers.displayNameHandler, handlers.componentMethodsHandler, handlers.componentMethodsJsDocHandler];

@@ -44,0 +44,0 @@ /**

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

if (propertyPath.node.computed) {
throw new TypeError('Propery name must be an Identifier or a Literal');
throw new TypeError('Property name must be an Identifier or a Literal');
}

@@ -24,0 +24,0 @@

@@ -61,2 +61,16 @@ 'use strict';

// check for @extends React.Component in docblock
if (path.parentPath && path.parentPath.value) {
var classDeclaration = Array.isArray(path.parentPath.value) ? path.parentPath.value.find(function (declaration) {
return declaration.type === 'ClassDeclaration';
}) : path.parentPath.value;
if (classDeclaration && classDeclaration.leadingComments && classDeclaration.leadingComments.some(function (comment) {
return (/@extends\s+React\.Component/.test(comment.value)
);
})) {
return true;
}
}
// extends ReactComponent?

@@ -63,0 +77,0 @@ if (!node.superClass) {

@@ -66,3 +66,6 @@ 'use strict';

if (types.ClassDeclaration.check(classDefinition.node)) {
variableName = classDefinition.node.id.name;
// Class declarations don't have an id, e.g.: `export default class extends React.Component {}`
if (classDefinition.node.id) {
variableName = classDefinition.node.id.name;
}
} else if (types.ClassExpression.check(classDefinition.node)) {

@@ -69,0 +72,0 @@ var parentPath = classDefinition.parentPath;

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

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

"babel-core": "^6.26.0",
"babel-eslint": "^7.0.0",
"babel-eslint": "^8.2.2",
"babel-jest": "^21.2.0",

@@ -54,3 +54,3 @@ "babel-plugin-transform-object-rest-spread": "^6.26.0",

"cross-spawn": "^5.0.0",
"eslint": "^4.3.0",
"eslint": "^4.18.1",
"flow-bin": "^0.59.0",

@@ -57,0 +57,0 @@ "jest": "^21.2.1",

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