react-docgen
Advanced tools
Comparing version 3.0.0-rc.0 to 3.0.0-rc.1
@@ -1,24 +0,24 @@ | ||
"use strict"; | ||
'use strict'; | ||
var _from = require("babel-runtime/core-js/array/from"); | ||
var _from = require('babel-runtime/core-js/array/from'); | ||
var _from2 = _interopRequireDefault(_from); | ||
var _keys = require("babel-runtime/core-js/object/keys"); | ||
var _keys = require('babel-runtime/core-js/object/keys'); | ||
var _keys2 = _interopRequireDefault(_keys); | ||
var _getIterator2 = require("babel-runtime/core-js/get-iterator"); | ||
var _getIterator2 = require('babel-runtime/core-js/get-iterator'); | ||
var _getIterator3 = _interopRequireDefault(_getIterator2); | ||
var _slicedToArray2 = require("babel-runtime/helpers/slicedToArray"); | ||
var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray'); | ||
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2); | ||
var _set = require("babel-runtime/core-js/set"); | ||
var _set = require('babel-runtime/core-js/set'); | ||
var _set2 = _interopRequireDefault(_set); | ||
var _map = require("babel-runtime/core-js/map"); | ||
var _map = require('babel-runtime/core-js/map'); | ||
@@ -29,2 +29,14 @@ var _map2 = _interopRequireDefault(_map); | ||
/* | ||
* 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. | ||
* | ||
* | ||
* | ||
*/ | ||
class Documentation { | ||
@@ -217,14 +229,4 @@ | ||
} | ||
} /* | ||
* 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. | ||
* | ||
* | ||
* | ||
*/ | ||
} | ||
module.exports = Documentation; |
@@ -127,3 +127,12 @@ 'use strict'; | ||
if (types.QualifiedTypeIdentifier.check(path.node.id)) { | ||
type = handleQualifiedTypeIdentifier(path.get('id')); | ||
const id = path.get('id'); | ||
if (id.node.qualification.name === 'React') { | ||
type = { | ||
name: `${id.node.qualification.name}${id.node.id.name}`, | ||
raw: (0, _printValue2.default)(id) | ||
}; | ||
} else { | ||
type = { name: (0, _printValue2.default)(id).replace(/<.*>$/, '') }; | ||
} | ||
} else { | ||
@@ -231,3 +240,7 @@ type = { name: path.node.id.name }; | ||
function handleTupleTypeAnnotation(path) { | ||
const type = { name: 'tuple', raw: (0, _printValue2.default)(path), elements: [] }; | ||
const type = { | ||
name: 'tuple', | ||
raw: (0, _printValue2.default)(path), | ||
elements: [] | ||
}; | ||
@@ -245,8 +258,2 @@ path.get('types').each(param => { | ||
function handleQualifiedTypeIdentifier(path) { | ||
if (path.node.qualification.name !== 'React') return null; | ||
return { name: `React${path.node.id.name}`, raw: (0, _printValue2.default)(path) }; | ||
} | ||
let visitedTypes = {}; | ||
@@ -253,0 +260,0 @@ |
@@ -94,2 +94,6 @@ 'use strict'; | ||
if (methodPath.node.kind === 'get' || methodPath.node.kind === 'set') { | ||
modifiers.push(methodPath.node.kind); | ||
} | ||
const functionExpression = methodPath.get('value').node; | ||
@@ -96,0 +100,0 @@ if (functionExpression.generator) { |
@@ -194,14 +194,3 @@ 'use strict'; | ||
const simplePropTypes = { | ||
array: 1, | ||
bool: 1, | ||
func: 1, | ||
number: 1, | ||
object: 1, | ||
string: 1, | ||
any: 1, | ||
element: 1, | ||
node: 1, | ||
symbol: 1 | ||
}; | ||
const simplePropTypes = ['array', 'bool', 'func', 'number', 'object', 'string', 'any', 'element', 'node', 'symbol']; | ||
@@ -236,3 +225,3 @@ const propTypes = { | ||
if (name) { | ||
if (simplePropTypes.hasOwnProperty(name)) { | ||
if (simplePropTypes.includes(name)) { | ||
descriptor = { name }; | ||
@@ -248,3 +237,3 @@ return true; | ||
const node = path.node; | ||
if (types.Identifier.check(node) && simplePropTypes.hasOwnProperty(node.name)) { | ||
if (types.Identifier.check(node) && simplePropTypes.includes(node.name)) { | ||
descriptor = { name: node.name }; | ||
@@ -251,0 +240,0 @@ } else if (types.CallExpression.check(node) && types.Identifier.check(node.callee) && propTypes.hasOwnProperty(node.callee.name)) { |
@@ -14,18 +14,49 @@ 'use strict'; | ||
function getType(tag) { | ||
if (!tag.type) { | ||
function getType(tagType) { | ||
if (!tagType) { | ||
return null; | ||
} else if (tag.type.type === 'UnionType') { | ||
// union type | ||
return { | ||
name: 'union', | ||
value: tag.type.elements.map(function (element) { | ||
return element.name; | ||
}) | ||
}; | ||
} else if (tag.type.type === 'AllLiteral') { | ||
// return {*} | ||
return { name: 'mixed' }; | ||
} | ||
return { name: tag.type.name ? tag.type.name : tag.type.expression.name }; | ||
const type = tagType.type, | ||
name = tagType.name, | ||
expression = tagType.expression, | ||
elements = tagType.elements, | ||
applications = tagType.applications; | ||
switch (type) { | ||
case 'NameExpression': | ||
// {a} | ||
return { name }; | ||
case 'UnionType': | ||
// {a|b} | ||
return { | ||
name: 'union', | ||
elements: elements.map(element => getType(element)) | ||
}; | ||
case 'AllLiteral': | ||
// {*} | ||
return { name: 'mixed' }; | ||
case 'TypeApplication': | ||
// {Array<string>} or {string[]} | ||
return { | ||
name: expression.name, | ||
elements: applications.map(element => getType(element)) | ||
}; | ||
case 'ArrayType': | ||
// {[number, string]} | ||
return { | ||
name: 'tuple', | ||
elements: elements.map(element => getType(element)) | ||
}; | ||
default: | ||
{ | ||
const typeName = name ? name : expression ? expression.name : null; | ||
if (typeName) { | ||
return { name: typeName }; | ||
} else { | ||
return null; | ||
} | ||
} | ||
} | ||
} /* | ||
@@ -43,6 +74,3 @@ * Copyright (c) 2015, Facebook, Inc. | ||
function getOptional(tag) { | ||
if (tag.type && tag.type.type && tag.type.type === 'OptionalType') { | ||
return true; | ||
} | ||
return undefined; | ||
return !!(tag.type && tag.type.type && tag.type.type === 'OptionalType'); | ||
} | ||
@@ -56,3 +84,3 @@ | ||
description: returnTag.description, | ||
type: getType(returnTag) | ||
type: getType(returnTag.type) | ||
}; | ||
@@ -72,3 +100,3 @@ } | ||
description: tag.description, | ||
type: getType(tag), | ||
type: getType(tag.type), | ||
optional: getOptional(tag) | ||
@@ -75,0 +103,0 @@ }; |
{ | ||
"name": "react-docgen", | ||
"version": "3.0.0-rc.0", | ||
"version": "3.0.0-rc.1", | ||
"description": "A CLI and toolkit to extract information from React components for documentation generation.", | ||
@@ -23,3 +23,3 @@ "repository": { | ||
"scripts": { | ||
"build": "rimraf dist/ && babel src/ --out-dir dist/ --ignore __tests__,__mocks__", | ||
"build": "rimraf dist/ && babel src/ --out-dir dist/ --ignore __tests__,__mocks__,src/types.js", | ||
"lint": "eslint . --report-unused-disable-directives", | ||
@@ -26,0 +26,0 @@ "fix": "eslint . --fix --report-unused-disable-directives", |
@@ -48,2 +48,3 @@ # react-docgen [![Build Status](https://travis-ci.org/reactjs/react-docgen.svg?branch=master)](https://travis-ci.org/reactjs/react-docgen) | ||
path to a module that exports a resolver. [findExportedComponentDefinition] | ||
--legacy-decorators Switch parsing to support only the legacy decorators syntax | ||
@@ -80,3 +81,3 @@ Extract meta information from React components. | ||
### parse(source \[, resolver \[, handlers\]\]) | ||
### parse(source \[, resolver \[, handlers \[, options\]\]\]) | ||
@@ -87,3 +88,4 @@ | Parameter | Type | Description | | ||
| resolver | function | A function of the form `(ast: ASTNode, recast: Object) => (NodePath|Array<NodePath>)`. Given an AST and a reference to recast, it returns an (array of) NodePath which represents the component definition. | | ||
| handlers | Array\<function\> | An array of functions of the form `(documentation: Documentation, definition: NodePath) => void`. Each function is called with a `Documentation` object and a reference to the component definition as returned by `resolver`. Handlers extract relevant information from the definition and augment `documentation`. | | ||
| handlers | Array\<function\> | An array of functions of the form `(documentation: Documentation, definition: NodePath) => void`. Each function is called with a `Documentation` object and a reference to the component definition as returned by `resolver`. Handlers extract relevant information from the definition and augment `documentation`. | | ||
| options | Object | Pass options to react-docgen. Supported option is `legacyDecorators` which is a boolean | | ||
@@ -90,0 +92,0 @@ #### resolver |
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
204132
4768
396