react-docgen-typescript
Advanced tools
Comparing version
@@ -7,11 +7,10 @@ "use strict"; | ||
if (required === void 0) { required = false; } | ||
if (defaultValue === void 0) { defaultValue = undefined; } | ||
if (description === void 0) { description = ''; } | ||
if (type === void 0) { type = { name: 'string' }; } | ||
return { | ||
defaultValue: defaultValue, | ||
description: description, | ||
name: name, | ||
type: type, | ||
required: required, | ||
defaultValue: defaultValue, | ||
description: description | ||
type: type | ||
}; | ||
@@ -27,3 +26,5 @@ } | ||
var filterFn = buildFilter_1.buildFilter(opts); | ||
chai_1.expect([prop1, prop2, children].filter(function (prop) { return filterFn(prop, { name: prop.name }); })).to.eql([prop1, prop2]); | ||
chai_1.expect([prop1, prop2, children].filter(function (prop) { | ||
return filterFn(prop, { name: prop.name }); | ||
})).to.eql([prop1, prop2]); | ||
}); | ||
@@ -36,3 +37,5 @@ it('should not skip "children" property if description is set', function () { | ||
var filterFn = buildFilter_1.buildFilter(opts); | ||
chai_1.expect([prop1, prop2, children].filter(function (prop) { return filterFn(prop, { name: prop.name }); })).to.eql([prop1, prop2, children]); | ||
chai_1.expect([prop1, prop2, children].filter(function (prop) { | ||
return filterFn(prop, { name: prop.name }); | ||
})).to.eql([prop1, prop2, children]); | ||
}); | ||
@@ -59,3 +62,5 @@ }); | ||
var filterFn = buildFilter_1.buildFilter(opts); | ||
chai_1.expect([prop1, prop2, prop3].filter(function (prop) { return filterFn(prop, { name: prop.name }); })).to.eql([prop2]); | ||
chai_1.expect([prop1, prop2, prop3].filter(function (prop) { | ||
return filterFn(prop, { name: prop.name }); | ||
})).to.eql([prop2]); | ||
}); | ||
@@ -84,3 +89,5 @@ }); | ||
var filterFn = buildFilter_1.buildFilter(opts); | ||
chai_1.expect([prop1, prop2, prop3].filter(function (prop) { return filterFn(prop, { name: prop.name }); })).to.eql([prop2]); | ||
chai_1.expect([prop1, prop2, prop3].filter(function (prop) { | ||
return filterFn(prop, { name: prop.name }); | ||
})).to.eql([prop2]); | ||
}); | ||
@@ -95,3 +102,5 @@ it('should get be possible to filter by component name', function () { | ||
var filterFn = buildFilter_1.buildFilter(opts); | ||
chai_1.expect([prop1, prop2, prop3].filter(function (prop) { return filterFn(prop, { name: prop.name.toUpperCase() }); })).to.eql([prop1]); | ||
chai_1.expect([prop1, prop2, prop3].filter(function (prop) { | ||
return filterFn(prop, { name: prop.name.toUpperCase() }); | ||
})).to.eql([prop1]); | ||
}); | ||
@@ -98,0 +107,0 @@ }); |
@@ -5,3 +5,3 @@ "use strict"; | ||
describe('parser', function () { | ||
var children = { type: 'ReactNode', required: false, description: '', }; | ||
var children = { type: 'ReactNode', required: false, description: '' }; | ||
it('should parse simple react class component', function () { | ||
@@ -13,3 +13,3 @@ testUtils_1.check('Column', { | ||
prop3: { type: '() => void' }, | ||
prop4: { type: '"option1" | "option2" | "option3"' }, | ||
prop4: { type: '"option1" | "option2" | "option3"' } | ||
} | ||
@@ -24,3 +24,3 @@ }); | ||
prop3: { type: '() => void' }, | ||
prop4: { type: '"option1" | "option2" | "option3"' }, | ||
prop4: { type: '"option1" | "option2" | "option3"' } | ||
} | ||
@@ -35,3 +35,3 @@ }); | ||
prop3: { type: '() => void' }, | ||
prop4: { type: '"option1" | "option2" | "option3"' }, | ||
prop4: { type: '"option1" | "option2" | "option3"' } | ||
} | ||
@@ -46,3 +46,3 @@ }); | ||
prop3: { type: '() => void' }, | ||
prop4: { type: '"option1" | "option2" | "option3"' }, | ||
prop4: { type: '"option1" | "option2" | "option3"' } | ||
} | ||
@@ -54,3 +54,3 @@ }); | ||
AppMenu: { | ||
menu: { type: 'any' }, | ||
menu: { type: 'any' } | ||
} | ||
@@ -65,3 +65,3 @@ }); | ||
prop2: { type: 'number', description: '' }, | ||
propx: { type: 'number' }, | ||
propx: { type: 'number' } | ||
} | ||
@@ -72,19 +72,19 @@ }); | ||
testUtils_1.check('ColumnHigherOrderComponent', { | ||
ColumnExternalHigherOrderComponent: { | ||
prop1: { type: 'string' } | ||
}, | ||
ColumnHigherOrderComponent1: { | ||
prop1: { type: 'string' }, | ||
prop1: { type: 'string' } | ||
}, | ||
ColumnHigherOrderComponent2: { | ||
prop1: { type: 'string' }, | ||
prop1: { type: 'string' } | ||
}, | ||
RowExternalHigherOrderComponent: { | ||
prop1: { type: 'string' } | ||
}, | ||
RowHigherOrderComponent1: { | ||
prop1: { type: 'string' }, | ||
prop1: { type: 'string' } | ||
}, | ||
RowHigherOrderComponent2: { | ||
prop1: { type: 'string' }, | ||
}, | ||
ColumnExternalHigherOrderComponent: { | ||
prop1: { type: 'string' }, | ||
}, | ||
RowExternalHigherOrderComponent: { | ||
prop1: { type: 'string' }, | ||
prop1: { type: 'string' } | ||
} | ||
@@ -96,2 +96,3 @@ }); | ||
Column: { | ||
// tslint:disable:object-literal-sort-keys | ||
prop1: { type: 'string', required: false }, | ||
@@ -106,2 +107,3 @@ prop2: { type: 'number' }, | ||
// ... | ||
// tslint:enable:object-literal-sort-keys | ||
} | ||
@@ -114,3 +116,3 @@ }, false); | ||
prop1: { type: 'string', required: false }, | ||
prop2: { type: 'number' }, | ||
prop2: { type: 'number' } | ||
} | ||
@@ -123,3 +125,3 @@ }); | ||
prop1: { type: 'string', required: false }, | ||
prop2: { type: 'number' }, | ||
prop2: { type: 'number' } | ||
}, | ||
@@ -133,3 +135,3 @@ // TODO: this wasn't there before, i would guess that that's correct | ||
ExternalPropsComponent: { | ||
prop1: { type: 'string' }, | ||
prop1: { type: 'string' } | ||
} | ||
@@ -142,3 +144,3 @@ }); | ||
prop1: { type: 'number', required: false, description: 'prop1' }, | ||
prop2: { type: 'string', required: false, description: 'prop2' }, | ||
prop2: { type: 'string', required: false, description: 'prop2' } | ||
} | ||
@@ -151,3 +153,3 @@ }); | ||
isFlippedX: { type: 'boolean', required: false }, | ||
isFlippedY: { type: 'boolean', required: false }, | ||
isFlippedY: { type: 'boolean', required: false } | ||
} | ||
@@ -159,3 +161,3 @@ }, false); | ||
MyComponent: { | ||
foo: { type: 'any' }, | ||
foo: { type: 'any' } | ||
} | ||
@@ -167,9 +169,31 @@ }); | ||
ComponentWithDefaultProps: { | ||
sampleDefaultFromJSDoc: { type: '"hello" | "goodbye"', required: true, defaultValue: "hello", description: 'sample with default value' }, | ||
sampleTrue: { type: "boolean", required: false, defaultValue: "true" }, | ||
sampleFalse: { type: "boolean", required: false, defaultValue: "false" }, | ||
sampleString: { type: "string", required: false, defaultValue: "hello" }, | ||
sampleObject: { type: "{ [key: string]: any; }", required: false, defaultValue: "{ a: '1', b: 2, c: true, d: false, e: undefined, f: null, g: { a: '1' } }" }, | ||
sampleNull: { type: "null", required: false, defaultValue: "null" }, | ||
sampleUndefined: { type: "any", required: false, defaultValue: "undefined" }, | ||
sampleDefaultFromJSDoc: { | ||
defaultValue: 'hello', | ||
description: 'sample with default value', | ||
required: true, | ||
type: '"hello" | "goodbye"' | ||
}, | ||
sampleFalse: { | ||
defaultValue: 'false', | ||
required: false, | ||
type: 'boolean' | ||
}, | ||
sampleNull: { type: 'null', required: false, defaultValue: 'null' }, | ||
sampleNumber: { type: 'number', required: false, defaultValue: '-1' }, | ||
sampleObject: { | ||
defaultValue: "{ a: '1', b: 2, c: true, d: false, e: undefined, f: null, g: { a: '1' } }", | ||
required: false, | ||
type: '{ [key: string]: any; }' | ||
}, | ||
sampleString: { | ||
defaultValue: 'hello', | ||
required: false, | ||
type: 'string' | ||
}, | ||
sampleTrue: { type: 'boolean', required: false, defaultValue: 'true' }, | ||
sampleUndefined: { | ||
defaultValue: 'undefined', | ||
required: false, | ||
type: 'any' | ||
} | ||
} | ||
@@ -182,3 +206,3 @@ }); | ||
prop1: { type: 'string', required: false }, | ||
prop2: { type: 'number' }, | ||
prop2: { type: 'number' } | ||
} | ||
@@ -200,3 +224,3 @@ }); | ||
prop1: { type: 'string', required: false }, | ||
prop2: { type: 'number' }, | ||
prop2: { type: 'number' } | ||
} | ||
@@ -208,3 +232,3 @@ }); | ||
Stateless: { | ||
myProp: { type: 'string' }, | ||
myProp: { type: 'string' } | ||
} | ||
@@ -216,4 +240,4 @@ }); | ||
StatelessWithDefaultProps: { | ||
sampleJSDoc: { type: "string", required: false, defaultValue: "test" }, | ||
sampleProp: { type: "string", required: false, defaultValue: "hello" }, | ||
sampleJSDoc: { type: 'string', required: false, defaultValue: 'test' }, | ||
sampleProp: { type: 'string', required: false, defaultValue: 'hello' } | ||
} | ||
@@ -225,3 +249,3 @@ }); | ||
Jumbotron: { | ||
prop1: { type: "string", required: true }, | ||
prop1: { type: 'string', required: true } | ||
} | ||
@@ -233,3 +257,3 @@ }); | ||
Jumbotron: { | ||
prop1: { type: "string", required: true }, | ||
prop1: { type: 'string', required: true } | ||
} | ||
@@ -241,3 +265,3 @@ }); | ||
Jumbotron: { | ||
prop1: { type: "string", required: true }, | ||
prop1: { type: 'string', required: true } | ||
} | ||
@@ -250,3 +274,3 @@ }); | ||
FunctionalComponentAsConstAsDefaultExport: { | ||
prop1: { type: "string", required: true }, | ||
prop1: { type: 'string', required: true } | ||
} | ||
@@ -259,3 +283,3 @@ }, true, 'Jumbotron description'); | ||
FunctionalComponentAsConstAsNamedExport: { | ||
prop1: { type: "string", required: true }, | ||
prop1: { type: 'string', required: true } | ||
} | ||
@@ -273,3 +297,3 @@ }, true, 'Jumbotron description'); | ||
prop3: { type: '() => void' }, | ||
prop4: { type: '"option1" | "option2" | "option3"' }, | ||
prop4: { type: '"option1" | "option2" | "option3"' } | ||
} | ||
@@ -281,3 +305,7 @@ }, true); | ||
Column: { | ||
children: { type: 'ReactNode', required: false, description: 'children description' }, | ||
children: { | ||
description: 'children description', | ||
required: false, | ||
type: 'ReactNode' | ||
}, | ||
prop1: { type: 'string', required: false }, | ||
@@ -293,3 +321,5 @@ prop2: { type: 'number' }, | ||
it('should apply filter function and filter components accordingly', function () { | ||
var propFilter = function (prop, component) { return prop.name !== 'prop1'; }; | ||
var propFilter = function (prop, component) { | ||
return prop.name !== 'prop1'; | ||
}; | ||
testUtils_1.check('Column', { | ||
@@ -301,3 +331,3 @@ Column: { | ||
} | ||
}, true, null, { propFilter: propFilter }); | ||
}, true, undefined, { propFilter: propFilter }); | ||
}); | ||
@@ -317,8 +347,8 @@ it('should apply filter function and filter components accordingly', function () { | ||
} | ||
}, true, null, { propFilter: propFilter }); | ||
}, true, undefined, { propFilter: propFilter }); | ||
testUtils_1.check('AppMenu', { | ||
AppMenu: { | ||
menu: { type: 'any' }, | ||
menu: { type: 'any' } | ||
} | ||
}, true, null, { propFilter: propFilter }); | ||
}, true, undefined, { propFilter: propFilter }); | ||
}); | ||
@@ -335,3 +365,3 @@ }); | ||
} | ||
}, true, null, { propFilter: propFilter }); | ||
}, true, undefined, { propFilter: propFilter }); | ||
}); | ||
@@ -345,3 +375,3 @@ it('should skip multiple properties in skipPropsWithName', function () { | ||
} | ||
}, true, null, { propFilter: propFilter }); | ||
}, true, undefined, { propFilter: propFilter }); | ||
}); | ||
@@ -357,3 +387,3 @@ }); | ||
} | ||
}, true, null, { propFilter: propFilter }); | ||
}, true, undefined, { propFilter: propFilter }); | ||
}); | ||
@@ -360,0 +390,0 @@ }); |
@@ -8,3 +8,2 @@ "use strict"; | ||
if (exactProperties === void 0) { exactProperties = true; } | ||
if (description === void 0) { description = null; } | ||
var fileName = path.join(__dirname, '../../src/__tests__/data', component + ".tsx"); // it's running in ./temp | ||
@@ -17,5 +16,6 @@ var result = parser_1.parse(fileName, parserOpts); | ||
if (exactProperties === void 0) { exactProperties = true; } | ||
if (description === void 0) { description = null; } | ||
var expectedComponentNames = Object.getOwnPropertyNames(expected); | ||
chai_1.assert.equal(actual.length, expectedComponentNames.length, "The number of expected components is different - \r\nexpected: " + expectedComponentNames + ", \r\nactual: " + actual.map(function (i) { return i.displayName; })); | ||
chai_1.assert.equal(actual.length, expectedComponentNames.length, | ||
// tslint:disable-next-line:max-line-length | ||
"The number of expected components is different - \r\nexpected: " + expectedComponentNames + ", \r\nactual: " + actual.map(function (i) { return i.displayName; })); | ||
var errors = []; | ||
@@ -33,8 +33,10 @@ var _loop_1 = function (expectedComponentName) { | ||
var compName = componentDoc.displayName; | ||
var expectedComponentDescription = description | ||
|| compName + " description"; | ||
var expectedComponentDescription = description || compName + " description"; | ||
if (componentDoc.description !== expectedComponentDescription) { | ||
// tslint:disable-next-line:max-line-length | ||
errors.push(compName + " description is different - expected: '" + compName + " description', actual: '" + componentDoc.description + "'"); | ||
} | ||
if (propNames.length !== expectedPropNames.length && exactProperties === true) { | ||
if (propNames.length !== expectedPropNames.length && | ||
exactProperties === true) { | ||
// tslint:disable-next-line:max-line-length | ||
errors.push("Properties for " + compName + " are different - expected: " + expectedPropNames.length + ", actual: " + propNames.length + " (" + JSON.stringify(expectedPropNames) + ", " + JSON.stringify(propNames) + ")"); | ||
@@ -51,15 +53,26 @@ } | ||
if (expectedProp.type !== prop.type.name) { | ||
// tslint:disable-next-line:max-line-length | ||
errors.push("Property '" + compName + "." + expectedPropName + "' type is different - expected: " + expectedProp.type + ", actual: " + prop.type.name); | ||
} | ||
var expectedDescription = expectedProp.description === undefined ? expectedPropName + " description" : expectedProp.description; | ||
var expectedDescription = expectedProp.description === undefined | ||
? expectedPropName + " description" | ||
: expectedProp.description; | ||
if (expectedDescription !== prop.description) { | ||
errors.push("Property '" + compName + "." + expectedPropName + "' description is different - expected: " + expectedDescription + ", actual: " + prop.description); | ||
errors.push( | ||
// tslint:disable-next-line:max-line-length | ||
"Property '" + compName + "." + expectedPropName + "' description is different - expected: " + expectedDescription + ", actual: " + prop.description); | ||
} | ||
var expectedRequired = expectedProp.required === undefined ? true : expectedProp.required; | ||
if (expectedRequired !== prop.required) { | ||
errors.push("Property '" + compName + "." + expectedPropName + "' required is different - expected: " + expectedRequired + ", actual: " + prop.required); | ||
errors.push( | ||
// tslint:disable-next-line:max-line-length | ||
"Property '" + compName + "." + expectedPropName + "' required is different - expected: " + expectedRequired + ", actual: " + prop.required); | ||
} | ||
var expectedDefaultValue = expectedProp.defaultValue; | ||
if (expectedDefaultValue && prop.defaultValue && expectedDefaultValue !== prop.defaultValue.value) { | ||
errors.push("Property '" + compName + "." + expectedPropName + "' defaultValue is different - expected: " + expectedDefaultValue + ", actual: " + prop.defaultValue.value); | ||
if (expectedDefaultValue && | ||
prop.defaultValue && | ||
expectedDefaultValue !== prop.defaultValue.value) { | ||
errors.push( | ||
// tslint:disable-next-line:max-line-length | ||
"Property '" + compName + "." + expectedPropName + "' defaultValue is different - expected: " + expectedDefaultValue + ", actual: " + prop.defaultValue.value); | ||
} | ||
@@ -75,2 +88,3 @@ } | ||
if (!ok) { | ||
// tslint:disable-next-line:no-console | ||
console.log(JSON.stringify(actual, null, 4)); | ||
@@ -77,0 +91,0 @@ } |
@@ -18,6 +18,8 @@ "use strict"; | ||
var _a = propFilter, skipPropsWithName = _a.skipPropsWithName, skipPropsWithoutDoc = _a.skipPropsWithoutDoc; | ||
if (typeof skipPropsWithName === 'string' && skipPropsWithName === prop.name) { | ||
if (typeof skipPropsWithName === 'string' && | ||
skipPropsWithName === prop.name) { | ||
return false; | ||
} | ||
else if (Array.isArray(skipPropsWithName) && skipPropsWithName.indexOf(prop.name) > -1) { | ||
else if (Array.isArray(skipPropsWithName) && | ||
skipPropsWithName.indexOf(prop.name) > -1) { | ||
return false; | ||
@@ -24,0 +26,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { parse, withDefaultConfig, withCustomConfig, ComponentDoc, Props, PropItem, PropItemType } from './parser'; | ||
import { ComponentDoc, parse, PropItem, PropItemType, Props, withCustomConfig, withDefaultConfig } from './parser'; | ||
export { parse, withDefaultConfig, withCustomConfig, ComponentDoc, Props, PropItem, PropItemType }; |
@@ -5,4 +5,4 @@ "use strict"; | ||
exports.parse = parser_1.parse; | ||
exports.withCustomConfig = parser_1.withCustomConfig; | ||
exports.withDefaultConfig = parser_1.withDefaultConfig; | ||
exports.withCustomConfig = parser_1.withCustomConfig; | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
var ts = require("typescript"); | ||
var path = require("path"); | ||
var fs = require("fs"); | ||
var buildFilter_1 = require("./buildFilter"); | ||
exports.defaultParserOpts = {}; | ||
var defaultOptions = { | ||
target: ts.ScriptTarget.Latest, | ||
jsx: ts.JsxEmit.React, | ||
module: ts.ModuleKind.CommonJS, | ||
jsx: ts.JsxEmit.React, | ||
target: ts.ScriptTarget.Latest | ||
}; | ||
@@ -55,2 +55,5 @@ /** | ||
var moduleSymbol = checker.getSymbolAtLocation(sourceFile); | ||
if (!moduleSymbol) { | ||
return []; | ||
} | ||
var exports = checker.getExportsOfModule(moduleSymbol); | ||
@@ -62,6 +65,8 @@ var components = exports | ||
var filteredComponents = components | ||
.filter(function (comp) { return !!comp; }) | ||
.filter(function (comp, index) { | ||
var isUnique = components | ||
.filter(function (cmp) { return !!cmp; }) | ||
.slice(index + 1) | ||
.filter(function (i) { return i.displayName === comp.displayName; }) | ||
.filter(function (innerComp) { return innerComp.displayName === comp.displayName; }) | ||
.length === 0; | ||
@@ -76,5 +81,5 @@ return isUnique; | ||
var defaultJSDoc = { | ||
description: '', | ||
fullComment: '', | ||
tags: {}, | ||
description: '' | ||
tags: {} | ||
}; | ||
@@ -87,4 +92,10 @@ var Parser = /** @class */ (function () { | ||
Parser.prototype.getComponentInfo = function (exp, source) { | ||
if (!!exp.declarations && exp.declarations.length === 0) { | ||
return null; | ||
} | ||
var type = this.checker.getTypeOfSymbolAtLocation(exp, exp.valueDeclaration || exp.declarations[0]); | ||
if (!exp.valueDeclaration) { | ||
if (!type.symbol) { | ||
return null; | ||
} | ||
exp = type.symbol; | ||
@@ -109,4 +120,4 @@ } | ||
return { | ||
description: this.findDocComment(exp).fullComment, | ||
displayName: componentName, | ||
description: this.findDocComment(exp).fullComment, | ||
props: props | ||
@@ -157,2 +168,5 @@ }; | ||
if (defaultProps === void 0) { defaultProps = {}; } | ||
if (!propsObj.valueDeclaration) { | ||
return {}; | ||
} | ||
var propsType = this.checker.getTypeOfSymbolAtLocation(propsObj, propsObj.valueDeclaration); | ||
@@ -166,2 +180,3 @@ var propertiesOfProps = propsType.getProperties(); | ||
var propTypeString = _this.checker.typeToString(propType); | ||
// tslint:disable-next-line:no-bitwise | ||
var isOptional = (prop.getFlags() & ts.SymbolFlags.Optional) !== 0; | ||
@@ -177,7 +192,7 @@ var jsDocComment = _this.findDocComment(prop); | ||
result[propName] = { | ||
defaultValue: defaultValue, | ||
description: jsDocComment.fullComment, | ||
name: propName, | ||
required: !isOptional, | ||
type: { name: propTypeString }, | ||
description: jsDocComment.fullComment, | ||
defaultValue: defaultValue | ||
type: { name: propTypeString } | ||
}; | ||
@@ -220,3 +235,5 @@ }); | ||
var currentValue = tagMap[tag.name]; | ||
tagMap[tag.name] = currentValue ? currentValue + '\n' + trimmedText : trimmedText; | ||
tagMap[tag.name] = currentValue | ||
? currentValue + '\n' + trimmedText | ||
: trimmedText; | ||
if (tag.name !== 'default') { | ||
@@ -226,11 +243,15 @@ tagComments.push(formatTag(tag)); | ||
}); | ||
return ({ | ||
return { | ||
description: mainComment, | ||
fullComment: (mainComment + '\n' + tagComments.join('\n')).trim(), | ||
tags: tagMap, | ||
description: mainComment | ||
}); | ||
tags: tagMap | ||
}; | ||
}; | ||
Parser.prototype.extractDefaultPropsFromComponent = function (symbol, source) { | ||
var _this = this; | ||
var possibleStatements = source.statements.filter(function (statement) { return _this.checker.getSymbolAtLocation(statement.name) === symbol; }); | ||
var possibleStatements = source.statements | ||
.filter(function (stmt) { return !!stmt.name; }) | ||
.filter(function (stmt) { | ||
return _this.checker.getSymbolAtLocation(stmt.name) === symbol; | ||
}); | ||
if (!possibleStatements.length) { | ||
@@ -250,4 +271,8 @@ return {}; | ||
var literalValue = getLiteralValueFromPropertyAssignment(property); | ||
if (typeof literalValue === 'string') { | ||
acc[getPropertyName(property.name)] = getLiteralValueFromPropertyAssignment(property); | ||
var propertyName = getPropertyName(property.name); | ||
if (typeof literalValue === 'string' && propertyName !== null) { | ||
var value = getLiteralValueFromPropertyAssignment(property); | ||
if (value !== null) { | ||
acc[propertyName] = value; | ||
} | ||
} | ||
@@ -286,2 +311,4 @@ return acc; | ||
return initializer.text.trim(); | ||
case ts.SyntaxKind.PrefixUnaryExpression: | ||
return initializer.getFullText().trim(); | ||
case ts.SyntaxKind.NumericLiteral: | ||
@@ -293,3 +320,5 @@ return "" + initializer.text; | ||
// can potentially find other identifiers in the source and map those in the future | ||
return initializer.text === 'undefined' ? 'undefined' : null; | ||
return initializer.text === 'undefined' | ||
? 'undefined' | ||
: null; | ||
case ts.SyntaxKind.ObjectLiteralExpression: | ||
@@ -296,0 +325,0 @@ // return the source text for an object literal |
{ | ||
"name": "react-docgen-typescript", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"precommit": "lint-staged", | ||
"tsc": "tsc", | ||
@@ -12,3 +13,8 @@ "prepublish": "tsc -d", | ||
"print": "npm run tsc && node ./lib/print.js", | ||
"print:sample1": "npm run tsc && node ./lib/print.js ./src/__tests__/data/ColumnHigherOrderComponent.tsx simple" | ||
"print:sample1": "npm run tsc && node ./lib/print.js ./src/__tests__/data/ColumnHigherOrderComponent.tsx simple", | ||
"lint": "tslint -c tslint.json 'src/**/*.{ts,tsx}'", | ||
"lint:fix": "npm run lint -- --fix", | ||
"prettier:base": "prettier --parser typescript --single-quote --trailing-comma none", | ||
"prettier:check": "npm run prettier:base -- -l \"src/**/*.{ts,tsx}\"", | ||
"prettier:write": "npm run prettier:base -- --write \"src/**/*.{ts,tsx}\"" | ||
}, | ||
@@ -24,5 +30,9 @@ "license": "MIT", | ||
"chai": "^4.1.2", | ||
"husky": "^0.14.3", | ||
"lint-staged": "^6.0.1", | ||
"mocha": "^4.1.0", | ||
"prettier": "^1.10.2", | ||
"react": "^15.4.2", | ||
"source-map-support": "^0.5.0", | ||
"tslint": "^5.9.1", | ||
"typescript": "^2.6.2" | ||
@@ -29,0 +39,0 @@ }, |
@@ -7,7 +7,7 @@ # react-docgen-typescript | ||
A simple parser for React properties defined in TypeScript instead of propTypes. | ||
A simple parser for React properties defined in TypeScript instead of propTypes. | ||
It can be used with [React Styleguidist](https://github.com/styleguidist/react-styleguidist). | ||
## Installation | ||
## Installation | ||
@@ -33,9 +33,20 @@ ``` | ||
### parserOptions | ||
- `skipPropsWithName?: string[] | string;` | ||
- `skipPropsWithoutDoc?: boolean;` | ||
or | ||
- propFilter: | ||
`(props: PropItem, component: Component) => boolean` | ||
```typescript | ||
{ | ||
skipPropsWithName?: string[] | string; | ||
skipPropsWithoutDoc?: boolean; | ||
} | ||
``` | ||
or | ||
```typescript | ||
(props: PropItem, component: Component) => boolean | ||
``` | ||
Note: `children` without a doc comment will not be documented. | ||
## Example | ||
@@ -59,4 +70,4 @@ | ||
prop2: number; | ||
/** | ||
* prop3 description | ||
/** | ||
* prop3 description | ||
*/ | ||
@@ -117,6 +128,6 @@ prop3: () => void; | ||
## Contributions | ||
The typescript is pretty complex and there are many different way how | ||
to define components and their props so it's realy hard to support all | ||
diferent use cases. That means only one thing, contributions are highly | ||
welcome. Just keep in mind that each PR should also include tests for | ||
The typescript is pretty complex and there are many different way how | ||
to define components and their props so it's realy hard to support all | ||
diferent use cases. That means only one thing, contributions are highly | ||
welcome. Just keep in mind that each PR should also include tests for | ||
the part it's fixing. | ||
@@ -126,16 +137,22 @@ | ||
@RoystonS Royston Shufflebotham - complete parser rewrite that use typescript parser in much better way and overcome many issues of previous implementation | ||
**@brettjurgens** *Brett Jurgens* - adding support for default props | ||
@JocD Jacques Dukes - complete support for functional components and much more | ||
**@diegolanda** *Diego* - support for different kinds of components | ||
@sapegin Artem Sapegin - fix for compatibility with react-styleguidist v5 | ||
**@dotcs** *Fabian Mueller* - introduced parserOptions for skipping undocumented properties | ||
@diegolanda Diego - support for different kinds of components | ||
**@Havret** *Krzysztof Havret* | ||
@brettjurgens Brett Jurgens - adding support for default props | ||
**@JakeSidSmith** *Jake* | ||
@dotcs Fabian Mueller - introduced parserOptions for skipping undocumented properties | ||
**@JocD** *Jacques Dukes* - complete support for functional components and much more | ||
**@jrwebdev** *James Ravenscroft* | ||
**@RoystonS** *Royston Shufflebotham* - complete parser rewrite that use typescript parser in much better way and overcome many issues of previous implementation | ||
**@sapegin** *Artem Sapegin* - fix for compatibility with react-styleguidist v5 | ||
## Thanks to others | ||
The integration with React Styleguidist wouldn't be possible without [Vyacheslav Slinko](https://github.com/vslinko) pull request [#118](https://github.com/styleguidist/react-styleguidist/pull/118) at React Styleguidist. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
85138
5.13%1054
8.66%154
12.41%14
40%