react-docgen
Advanced tools
Comparing version 3.0.0-rc.2 to 3.0.0
@@ -12,2 +12,4 @@ "use strict"; | ||
var _isReactForwardRefCall = _interopRequireDefault(require("../utils/isReactForwardRefCall")); | ||
var _isReactComponentClass = _interopRequireDefault(require("../utils/isReactComponentClass")); | ||
@@ -44,3 +46,3 @@ | ||
function isComponentDefinition(path) { | ||
return (0, _isReactCreateClassCall.default)(path) || (0, _isReactComponentClass.default)(path) || (0, _isStatelessComponent.default)(path); | ||
return (0, _isReactCreateClassCall.default)(path) || (0, _isReactComponentClass.default)(path) || (0, _isStatelessComponent.default)(path) || (0, _isReactForwardRefCall.default)(path); | ||
} | ||
@@ -61,2 +63,4 @@ | ||
return definition; | ||
} else if ((0, _isReactForwardRefCall.default)(definition)) { | ||
return definition; | ||
} | ||
@@ -63,0 +67,0 @@ |
@@ -75,3 +75,3 @@ "use strict"; | ||
value = value.get('argument', 'id'); | ||
} else { | ||
} else if (!types.ObjectTypeAnnotation.check(value.node)) { | ||
value = value.get('id'); | ||
@@ -82,4 +82,4 @@ } | ||
if (resolvedPath && types.ObjectExpression.check(resolvedPath.node)) { | ||
const keys = (0, _resolveObjectKeysToArray.resolveObjectExpressionToNameArray)(resolvedPath, true); | ||
if (resolvedPath && (types.ObjectExpression.check(resolvedPath.node) || types.ObjectTypeAnnotation.check(resolvedPath.node))) { | ||
const keys = (0, _resolveObjectKeysToArray.resolveObjectToNameArray)(resolvedPath, true); | ||
@@ -86,0 +86,0 @@ if (keys) { |
@@ -14,2 +14,4 @@ "use strict"; | ||
var _isReactForwardRefCall = _interopRequireDefault(require("./isReactForwardRefCall")); | ||
var _recast = _interopRequireDefault(require("recast")); | ||
@@ -46,3 +48,3 @@ | ||
if (types.FunctionExpression.check(path.node) || types.ArrowFunctionExpression.check(path.node) || types.TaggedTemplateExpression.check(path.node)) { | ||
if (types.FunctionExpression.check(path.node) || types.ArrowFunctionExpression.check(path.node) || types.TaggedTemplateExpression.check(path.node) || types.CallExpression.check(path.node) || (0, _isReactForwardRefCall.default)(path)) { | ||
let currentPath = path; | ||
@@ -61,3 +63,3 @@ | ||
throw new TypeError('Attempted to resolveName for an unsupported path. resolveName accepts a ' + 'VariableDeclaration, FunctionDeclaration, or FunctionExpression. Got "' + path.node.type + '".'); | ||
throw new TypeError('Attempted to resolveName for an unsupported path. resolveName accepts a ' + 'VariableDeclaration, FunctionDeclaration, FunctionExpression or CallExpression. Got "' + path.node.type + '".'); | ||
} | ||
@@ -64,0 +66,0 @@ |
@@ -41,2 +41,3 @@ "use strict"; | ||
[types.ArrowFunctionExpression.name]: _getMemberExpressionValuePath.default, | ||
[types.CallExpression.name]: _getMemberExpressionValuePath.default, | ||
[types.FunctionExpression.name]: _getMemberExpressionValuePath.default, | ||
@@ -60,3 +61,3 @@ [types.FunctionDeclaration.name]: _getMemberExpressionValuePath.default, | ||
* While react-docgen's built-in resolvers do not support resolving | ||
* TaggedTemplateExpression definitiona, third-party resolvers (such as | ||
* TaggedTemplateExpression definitions, third-party resolvers (such as | ||
* https://github.com/Jmeyering/react-docgen-annotation-resolver) could be | ||
@@ -66,3 +67,14 @@ * used to add these definitions. | ||
types.TaggedTemplateExpression.check(node) || // potential stateless function component | ||
types.VariableDeclaration.check(node) || types.ArrowFunctionExpression.check(node) || types.FunctionDeclaration.check(node) || types.FunctionExpression.check(node); | ||
types.VariableDeclaration.check(node) || types.ArrowFunctionExpression.check(node) || types.FunctionDeclaration.check(node) || types.FunctionExpression.check(node) || | ||
/** | ||
* Adds support for libraries such as | ||
* [system-components]{@link https://jxnblk.com/styled-system/system-components} that use | ||
* CallExpressions to generate components. | ||
* | ||
* While react-docgen's built-in resolvers do not support resolving | ||
* CallExpressions definitions, third-party resolvers (such as | ||
* https://github.com/Jmeyering/react-docgen-annotation-resolver) could be | ||
* used to add these definitions. | ||
*/ | ||
types.CallExpression.check(node); | ||
} | ||
@@ -86,3 +98,3 @@ /** | ||
if (!isSupportedDefinitionType(componentDefinition)) { | ||
throw new TypeError('Got unsupported definition type. Definition must be one of ' + 'ObjectExpression, ClassDeclaration, ClassExpression,' + 'VariableDeclaration, ArrowFunctionExpression, FunctionExpression, ' + 'TaggedTemplateExpression or FunctionDeclaration. Got "' + componentDefinition.node.type + '"' + 'instead.'); | ||
throw new TypeError('Got unsupported definition type. Definition must be one of ' + 'ObjectExpression, ClassDeclaration, ClassExpression,' + 'VariableDeclaration, ArrowFunctionExpression, FunctionExpression, ' + 'TaggedTemplateExpression, FunctionDeclaration or CallExpression. Got "' + componentDefinition.node.type + '" instead.'); | ||
} | ||
@@ -89,0 +101,0 @@ |
@@ -26,2 +26,4 @@ "use strict"; | ||
var _resolveObjectValuesToArray = _interopRequireDefault(require("./resolveObjectValuesToArray")); | ||
/* | ||
@@ -77,3 +79,3 @@ * Copyright (c) 2015, Facebook, Inc. | ||
if (!types.ArrayExpression.check(value.node)) { | ||
value = (0, _resolveObjectKeysToArray.default)(value); | ||
value = (0, _resolveObjectKeysToArray.default)(value) || (0, _resolveObjectValuesToArray.default)(value); | ||
@@ -161,6 +163,10 @@ if (value) { | ||
} | ||
/** | ||
* Handles shape and exact prop types | ||
*/ | ||
function getPropTypeShape(argumentPath) { | ||
function getPropTypeShapish(name, argumentPath) { | ||
const type = { | ||
name: 'shape' | ||
name | ||
}; | ||
@@ -215,3 +221,4 @@ | ||
objectOf: getPropTypeObjectOf, | ||
shape: getPropTypeShape | ||
shape: getPropTypeShapish.bind(null, 'shape'), | ||
exact: getPropTypeShapish.bind(null, 'exact') | ||
}; | ||
@@ -218,0 +225,0 @@ /** |
@@ -8,3 +8,3 @@ "use strict"; | ||
}); | ||
exports.resolveObjectExpressionToNameArray = resolveObjectExpressionToNameArray; | ||
exports.resolveObjectToNameArray = resolveObjectToNameArray; | ||
exports.default = resolveObjectKeysToArray; | ||
@@ -37,18 +37,36 @@ | ||
function resolveObjectExpressionToNameArray(objectExpression, raw = false) { | ||
if (types.ObjectExpression.check(objectExpression.value) && objectExpression.value.properties.every(prop => types.Property.check(prop) && (types.Identifier.check(prop.key) && !prop.computed || types.Literal.check(prop.key)) || types.SpreadElement.check(prop))) { | ||
function isWhitelistedObjectProperty(prop) { | ||
return types.Property.check(prop) && (types.Identifier.check(prop.key) && !prop.computed || types.Literal.check(prop.key)) || types.SpreadElement.check(prop); | ||
} | ||
function isWhiteListedObjectTypeProperty(prop) { | ||
return types.ObjectTypeProperty.check(prop) || types.ObjectTypeSpreadProperty.check(prop); | ||
} // Resolves an ObjectExpression or an ObjectTypeAnnotation | ||
function resolveObjectToNameArray(object, raw = false) { | ||
if (types.ObjectExpression.check(object.value) && object.value.properties.every(isWhitelistedObjectProperty) || types.ObjectTypeAnnotation.check(object.value) && object.value.properties.every(isWhiteListedObjectTypeProperty)) { | ||
let values = []; | ||
let error = false; | ||
objectExpression.get('properties').each(propPath => { | ||
object.get('properties').each(propPath => { | ||
if (error) return; | ||
const prop = propPath.value; | ||
if (types.Property.check(prop)) { | ||
if (types.Property.check(prop) || types.ObjectTypeProperty.check(prop)) { | ||
// Key is either Identifier or Literal | ||
const name = prop.key.name || (raw ? prop.key.raw : prop.key.value); | ||
values.push(name); | ||
} else if (types.SpreadElement.check(prop)) { | ||
const spreadObject = (0, _resolveToValue.default)(propPath.get('argument')); | ||
const spreadValues = resolveObjectExpressionToNameArray(spreadObject); | ||
} else if (types.SpreadElement.check(prop) || types.ObjectTypeSpreadProperty.check(prop)) { | ||
let spreadObject = (0, _resolveToValue.default)(propPath.get('argument')); | ||
if (types.GenericTypeAnnotation.check(spreadObject.value)) { | ||
const typeAlias = (0, _resolveToValue.default)(spreadObject.get('id')); | ||
if (types.ObjectTypeAnnotation.check(typeAlias.get('right').value)) { | ||
spreadObject = (0, _resolveToValue.default)(typeAlias.get('right')); | ||
} | ||
} | ||
const spreadValues = resolveObjectToNameArray(spreadObject); | ||
if (!spreadValues) { | ||
@@ -86,3 +104,3 @@ error = true; | ||
const objectExpression = (0, _resolveToValue.default)(path.get('arguments').get(0)); | ||
const values = resolveObjectExpressionToNameArray(objectExpression); | ||
const values = resolveObjectToNameArray(objectExpression); | ||
@@ -89,0 +107,0 @@ if (values) { |
{ | ||
"name": "react-docgen", | ||
"version": "3.0.0-rc.2", | ||
"version": "3.0.0", | ||
"description": "A CLI and toolkit to extract information from React components for documentation generation.", | ||
@@ -61,3 +61,3 @@ "repository": { | ||
"eslint-plugin-prettier": "^3.0.0", | ||
"flow-bin": "^0.83.0", | ||
"flow-bin": "^0.87.0", | ||
"jest": "^23.6.0", | ||
@@ -64,0 +64,0 @@ "jest-diff": "^23.6.0", |
@@ -12,3 +12,3 @@ # react-docgen [![Build Status](https://travis-ci.org/reactjs/react-docgen.svg?branch=master)](https://travis-ci.org/reactjs/react-docgen) | ||
> react-docgen is a low level tool to extract information about react components. If you are searching for a more high level tool try [react-styleguidist](https://github.com/styleguidist/react-styleguidist) which comes with a complete styleguide and is build on top of react-docgen. | ||
> react-docgen is a low level tool to extract information about react components. If you are searching for a more high level styleguide with nice interface try [react-styleguidist](https://github.com/styleguidist/react-styleguidist) or any of the other tools listed in the [wiki](https://github.com/reactjs/react-docgen/wiki). | ||
@@ -24,7 +24,6 @@ ## Install | ||
``` | ||
npm install react-docgen | ||
npm install --save-dev react-docgen | ||
``` | ||
## CLI | ||
@@ -119,2 +118,4 @@ | ||
> There are some community created handlers available. Have a look at the wiki for a list: https://github.com/reactjs/react-docgen/wiki | ||
## Guidelines for default resolvers and handlers | ||
@@ -169,3 +170,3 @@ | ||
export default Component; | ||
export default MyComponent; | ||
``` | ||
@@ -172,0 +173,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
196501
71
4843
1
397