diff --git a/package-lock.json b/package-lock.json index 7c32babe..e5abc870 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "react-docgen-typescript", - "version": "1.20.1", + "version": "1.20.5", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2204,9 +2204,9 @@ "dev": true }, "prettier": { - "version": "1.12.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.12.1.tgz", - "integrity": "sha1-wa0g6APndJ+vkFpAnSNn4Gu+cyU=", + "version": "1.19.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", + "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", "dev": true }, "pretty-format": { diff --git a/package.json b/package.json index 69a32bac..c44de7d7 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "lint-staged": "^7.3.0", "lodash": "^4.17.15", "mocha": "^5.2.0", - "prettier": "^1.10.2", + "prettier": "^1.19.1", "prop-types": "^15.6.2", "react": "^16.4.2", "source-map-support": "^0.5.6", diff --git a/src/parser.ts b/src/parser.ts index 4ebb0c5d..3f8ea4c2 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -20,6 +20,7 @@ export interface ComponentDoc { description: string; props: Props; methods: Method[]; + tags?: {}; } export interface Props extends StringIndexedObject {} @@ -141,9 +142,7 @@ export function withCustomConfig( if (error !== undefined) { // tslint:disable-next-line: max-line-length - const errorText = `Cannot load custom tsconfig.json from provided path: ${tsconfigPath}, with error code: ${ - error.code - }, message: ${error.messageText}`; + const errorText = `Cannot load custom tsconfig.json from provided path: ${tsconfigPath}, with error code: ${error.code}, message: ${error.messageText}`; throw new Error(errorText); } @@ -231,9 +230,7 @@ export class Parser { this.savePropValueAsString = Boolean(savePropValueAsString); } - private getComponentFromExpression( - exp: ts.Symbol, - ) { + private getComponentFromExpression(exp: ts.Symbol) { const declaration = exp.valueDeclaration || exp.declarations![0]; const type = this.checker.getTypeOfSymbolAtLocation(exp, declaration); const typeSymbol = type.symbol || type.aliasSymbol; @@ -242,11 +239,11 @@ export class Parser { return exp; } - const symbolName = typeSymbol.getName() + const symbolName = typeSymbol.getName(); if ( - (symbolName === "MemoExoticComponent" || - symbolName === "ForwardRefExoticComponent") && + (symbolName === 'MemoExoticComponent' || + symbolName === 'ForwardRefExoticComponent') && exp.valueDeclaration && ts.isExportAssignment(exp.valueDeclaration) && ts.isCallExpression(exp.valueDeclaration.expression) @@ -332,7 +329,9 @@ export class Parser { const resolvedComponentName = componentNameResolver(nameSource, source); const { description, tags } = this.findDocComment(commentSource); const displayName = - resolvedComponentName || tags.visibleName || computeComponentName(nameSource, source); + resolvedComponentName || + tags.visibleName || + computeComponentName(nameSource, source); const methods = this.getMethodsInfo(type); if (propsType) { @@ -352,8 +351,8 @@ export class Parser { delete props[propName]; } } - return { + tags, description, displayName, methods, @@ -361,6 +360,7 @@ export class Parser { }; } else if (description && displayName) { return { + tags, description, displayName, methods, @@ -817,9 +817,9 @@ export class Parser { let propMap = {}; if (properties) { - propMap = this.getPropMap(properties as ts.NodeArray< - ts.PropertyAssignment - >); + propMap = this.getPropMap( + properties as ts.NodeArray + ); } return { @@ -849,9 +849,9 @@ export class Parser { if (right) { const { properties } = right as ts.ObjectLiteralExpression; if (properties) { - propMap = this.getPropMap(properties as ts.NodeArray< - ts.PropertyAssignment - >); + propMap = this.getPropMap( + properties as ts.NodeArray + ); } } }); @@ -954,31 +954,26 @@ export class Parser { public getPropMap( properties: ts.NodeArray ): StringIndexedObject { - const propMap = properties.reduce( - (acc, property) => { - if (ts.isSpreadAssignment(property) || !property.name) { - return acc; - } + const propMap = properties.reduce((acc, property) => { + if (ts.isSpreadAssignment(property) || !property.name) { + return acc; + } - const literalValue = this.getLiteralValueFromPropertyAssignment( - property - ); - const propertyName = getPropertyName(property.name); + const literalValue = this.getLiteralValueFromPropertyAssignment(property); + const propertyName = getPropertyName(property.name); - if ( - (typeof literalValue === 'string' || - typeof literalValue === 'number' || - typeof literalValue === 'boolean' || - literalValue === null) && - propertyName !== null - ) { - acc[propertyName] = literalValue; - } + if ( + (typeof literalValue === 'string' || + typeof literalValue === 'number' || + typeof literalValue === 'boolean' || + literalValue === null) && + propertyName !== null + ) { + acc[propertyName] = literalValue; + } - return acc; - }, - {} as StringIndexedObject - ); + return acc; + }, {} as StringIndexedObject); return propMap; }