react-docgen-typescript
Advanced tools
Comparing version
@@ -79,7 +79,6 @@ "use strict"; | ||
it('should parse simple react class component with picked properties', function () { | ||
// we are not able to get correct descriptions for prop1,prop2 | ||
testUtils_1.check('ColumnWithPick', { | ||
Column: { | ||
prop1: { type: 'string', required: false, description: '' }, | ||
prop2: { type: 'number', description: '' }, | ||
prop1: { type: 'string', required: false }, | ||
prop2: { type: 'number' }, | ||
propx: { type: 'number' } | ||
@@ -162,2 +161,23 @@ } | ||
}); | ||
it('should parse static sub components', function () { | ||
testUtils_1.check('StatelessStaticComponents', { | ||
StatelessStaticComponents: { | ||
myProp: { type: 'string' } | ||
}, | ||
'StatelessStaticComponents.Label': { | ||
title: { type: 'string' } | ||
} | ||
}); | ||
}); | ||
it('should parse static sub components on class components', function () { | ||
testUtils_1.check('ColumnWithStaticComponents', { | ||
Column: { | ||
prop1: { type: 'string' } | ||
}, | ||
'Column.Label': { | ||
title: { type: 'string' } | ||
}, | ||
'Column.SubLabel': {} | ||
}); | ||
}); | ||
it('should parse react component with properties extended from an external .tsx file', function () { | ||
@@ -387,3 +407,3 @@ testUtils_1.check('ExtendsExternalPropsComponent', { | ||
foo: { | ||
description: 'The foo prop should not repeat the description \nThe foo prop should not repeat the description', | ||
description: 'The foo prop should not repeat the description\nThe foo prop should not repeat the description', | ||
required: false, | ||
@@ -393,3 +413,3 @@ type: '"red" | "blue"' | ||
gap: { | ||
description: 'The space between children \nYou cannot use gap when using a "space" justify property', | ||
description: 'The space between children\nYou cannot use gap when using a "space" justify property', | ||
required: false, | ||
@@ -396,0 +416,0 @@ type: 'number' |
@@ -104,3 +104,4 @@ "use strict"; | ||
} | ||
var type = this.checker.getTypeOfSymbolAtLocation(exp, exp.valueDeclaration || exp.declarations[0]); | ||
var declaration = exp.valueDeclaration || exp.declarations[0]; | ||
var type = this.checker.getTypeOfSymbolAtLocation(exp, declaration); | ||
var commentSource = exp; | ||
@@ -135,2 +136,5 @@ var typeSymbol = type.symbol || type.aliasSymbol; | ||
} | ||
else if (type.symbol && (ts.isPropertyAccessExpression(declaration) || ts.isPropertyDeclaration(declaration))) { | ||
commentSource = type.symbol; | ||
} | ||
// Skip over PropTypes that are exported | ||
@@ -509,4 +513,4 @@ if (typeSymbol && | ||
if (ts.isShorthandPropertyAssignment(property)) { | ||
var symbol = this.checker.getShorthandAssignmentValueSymbol(property); | ||
var decl = symbol && symbol.valueDeclaration; | ||
var symbol_1 = this.checker.getShorthandAssignmentValueSymbol(property); | ||
var decl = symbol_1 && symbol_1.valueDeclaration; | ||
if (decl && decl.initializer) { | ||
@@ -737,3 +741,3 @@ initializer = decl.initializer; | ||
.filter(function (sourceFile) { | ||
return typeof sourceFile !== 'undefined'; | ||
return typeof sourceFile !== "undefined"; | ||
}) | ||
@@ -745,9 +749,32 @@ .reduce(function (docs, sourceFile) { | ||
} | ||
Array.prototype.push.apply(docs, checker | ||
.getExportsOfModule(moduleSymbol) | ||
.map(function (exp) { | ||
return parser.getComponentInfo(exp, sourceFile, parserOpts.componentNameResolver); | ||
}) | ||
.filter(function (comp) { return comp !== null; }) | ||
.filter(function (comp, index, comps) { | ||
var components = checker.getExportsOfModule(moduleSymbol); | ||
var componentDocs = []; | ||
// First document all components | ||
components.forEach(function (exp) { | ||
var doc = parser.getComponentInfo(exp, sourceFile, parserOpts.componentNameResolver); | ||
if (doc) { | ||
componentDocs.push(doc); | ||
} | ||
if (!exp.exports) { | ||
return; | ||
} | ||
// Then document any static sub-components | ||
exp.exports.forEach(function (symbol) { | ||
if (symbol.flags & ts.SymbolFlags.Prototype) { | ||
return; | ||
} | ||
if (symbol.flags & ts.SymbolFlags.Method) { | ||
var signature = parser.getCallSignature(symbol); | ||
var returnType = checker.typeToString(signature.getReturnType()); | ||
if (returnType !== 'Element') { | ||
return; | ||
} | ||
} | ||
var doc = parser.getComponentInfo(symbol, sourceFile, parserOpts.componentNameResolver); | ||
if (doc) { | ||
componentDocs.push(__assign({}, doc, { displayName: exp.escapedName + "." + symbol.escapedName })); | ||
} | ||
}); | ||
}); | ||
return docs.concat(componentDocs.filter(function (comp, index, comps) { | ||
return comps | ||
@@ -757,5 +784,4 @@ .slice(index + 1) | ||
})); | ||
return docs; | ||
}, []); | ||
} | ||
//# sourceMappingURL=parser.js.map |
{ | ||
"name": "react-docgen-typescript", | ||
"version": "1.17.1", | ||
"version": "1.18.0", | ||
"description": "", | ||
@@ -46,3 +46,3 @@ "homepage": "https://github.com/styleguidist/react-docgen-typescript/", | ||
"tslint": "^5.11.0", | ||
"typescript": "3.0.1" | ||
"typescript": "3.1.6" | ||
}, | ||
@@ -49,0 +49,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
173273
1.83%2286
2.05%