react-docgen-typescript
Advanced tools
Comparing version
@@ -6,1 +6,6 @@ /** ExternalPropsComponentProps props */ | ||
} | ||
/** ExternalOptionalComponentProps props */ | ||
export interface ExternalOptionalComponentProps { | ||
/** prop1 description */ | ||
prop1?: string; | ||
} |
@@ -29,2 +29,12 @@ "use strict"; | ||
}); | ||
it('should parse mulitple files', function () { | ||
var result = parser_1.parse([ | ||
testUtils_1.fixturePath('Column'), | ||
testUtils_1.fixturePath('ColumnWithDefaultExportOnly') | ||
]); | ||
testUtils_1.checkComponent(result, { | ||
Column: {}, | ||
ColumnWithDefaultExportOnly: {} | ||
}, false); | ||
}); | ||
it('should parse simple react class component as default export only', function () { | ||
@@ -227,2 +237,42 @@ testUtils_1.check('ColumnWithDefaultExportOnly', { | ||
}); | ||
it('should parse react stateless component with intersection props', function () { | ||
testUtils_1.check('StatelessIntersectionProps', { | ||
StatelessIntersectionProps: { | ||
moreProp: { type: 'number' }, | ||
myProp: { type: 'string' } | ||
} | ||
}); | ||
}); | ||
it('should parse react stateless component with external intersection props', function () { | ||
testUtils_1.check('StatelessIntersectionExternalProps', { | ||
StatelessIntersectionExternalProps: { | ||
myProp: { type: 'string' }, | ||
prop1: { type: 'string', required: false } | ||
} | ||
}); | ||
}); | ||
it('should parse react stateful component with intersection props', function () { | ||
testUtils_1.check('StatefulIntersectionProps', { | ||
StatefulIntersectionProps: { | ||
moreProp: { type: 'number' }, | ||
myProp: { type: 'string' } | ||
} | ||
}); | ||
}); | ||
it('should parse react stateful component with external intersection props', function () { | ||
testUtils_1.check('StatefulIntersectionExternalProps', { | ||
StatefulIntersectionExternalProps: { | ||
myProp: { type: 'string' }, | ||
prop1: { type: 'string', required: false } | ||
} | ||
}); | ||
}); | ||
it('should parse react stateful component (wrapped in HOC) with intersection props', function () { | ||
testUtils_1.check('HOCIntersectionProps', { | ||
HOCIntersectionProps: { | ||
injected: { type: 'boolean' }, | ||
myProp: { type: 'string' } | ||
} | ||
}); | ||
}); | ||
describe('stateless component with default props', function () { | ||
@@ -229,0 +279,0 @@ var expectation = { |
@@ -36,3 +36,3 @@ import * as ts from 'typescript'; | ||
export interface FileParser { | ||
parse(filePath: string): ComponentDoc[]; | ||
parse(filePathOrPaths: string | string[]): ComponentDoc[]; | ||
} | ||
@@ -43,3 +43,3 @@ /** | ||
*/ | ||
export declare function parse(filePath: string, parserOpts?: ParserOptions): ComponentDoc[]; | ||
export declare function parse(filePathOrPaths: string | string[], parserOpts?: ParserOptions): ComponentDoc[]; | ||
/** | ||
@@ -46,0 +46,0 @@ * Constructs a parser for a default configuration. |
@@ -17,5 +17,5 @@ "use strict"; | ||
*/ | ||
function parse(filePath, parserOpts) { | ||
function parse(filePathOrPaths, parserOpts) { | ||
if (parserOpts === void 0) { parserOpts = exports.defaultParserOpts; } | ||
return withCompilerOptions(defaultOptions, parserOpts).parse(filePath); | ||
return withCompilerOptions(defaultOptions, parserOpts).parse(filePathOrPaths); | ||
} | ||
@@ -55,30 +55,30 @@ exports.parse = parse; | ||
return { | ||
parse: function (filePath) { | ||
var program = ts.createProgram([filePath], compilerOptions); | ||
parse: function (filePathOrPaths) { | ||
var filePaths = Array.isArray(filePathOrPaths) | ||
? filePathOrPaths | ||
: [filePathOrPaths]; | ||
var program = ts.createProgram(filePaths, compilerOptions); | ||
var parser = new Parser(program, parserOpts); | ||
var checker = program.getTypeChecker(); | ||
var sourceFile = program.getSourceFile(filePath); | ||
if (!sourceFile) { | ||
return []; | ||
} | ||
var moduleSymbol = checker.getSymbolAtLocation(sourceFile); | ||
if (!moduleSymbol) { | ||
return []; | ||
} | ||
var exports = checker.getExportsOfModule(moduleSymbol); | ||
var components = exports | ||
.map(function (exp) { return parser.getComponentInfo(exp, sourceFile); }) | ||
.filter(function (comp) { return comp; }); | ||
// this should filter out components with the same name as default export | ||
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 (innerComp) { return innerComp.displayName === comp.displayName; }) | ||
.length === 0; | ||
return isUnique; | ||
}); | ||
return filteredComponents; | ||
return filePaths | ||
.map(function (filePath) { return program.getSourceFile(filePath); }) | ||
.filter(function (sourceFile) { | ||
return typeof sourceFile !== 'undefined'; | ||
}) | ||
.reduce(function (docs, sourceFile) { | ||
var moduleSymbol = checker.getSymbolAtLocation(sourceFile); | ||
if (!moduleSymbol) { | ||
return docs; | ||
} | ||
Array.prototype.push.apply(docs, checker | ||
.getExportsOfModule(moduleSymbol) | ||
.map(function (exp) { return parser.getComponentInfo(exp, sourceFile); }) | ||
.filter(function (comp) { return comp !== null; }) | ||
.filter(function (comp, index, comps) { | ||
return comps | ||
.slice(index + 1) | ||
.every(function (innerComp) { return innerComp.displayName !== comp.displayName; }); | ||
})); | ||
return docs; | ||
}, []); | ||
} | ||
@@ -235,3 +235,3 @@ }; | ||
} | ||
var mainComment = ts.displayPartsToString(symbol.getDocumentationComment()); | ||
var mainComment = ts.displayPartsToString(symbol.getDocumentationComment(this.checker)); | ||
var tags = symbol.getJsDocTags() || []; | ||
@@ -259,2 +259,3 @@ var tagComments = []; | ||
var possibleStatements = source.statements | ||
// ensure that name property is available | ||
.filter(function (stmt) { return !!stmt.name; }) | ||
@@ -261,0 +262,0 @@ .filter(function (stmt) { |
{ | ||
"name": "react-docgen-typescript", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "", | ||
@@ -37,3 +37,3 @@ "main": "lib/index.js", | ||
"tslint": "^5.9.1", | ||
"typescript": "^2.6.2" | ||
"typescript": "2.9.1" | ||
}, | ||
@@ -40,0 +40,0 @@ "files": [ |
@@ -157,2 +157,8 @@ # react-docgen-typescript | ||
**@kbukum** *Kamil BUKUM* | ||
**@marionebl** *Mario Nebl* | ||
**@milesj** *Miles Johnson* | ||
**@RoystonS** *Royston Shufflebotham* - complete parser rewrite that use typescript parser in much better way and overcome many issues of previous implementation | ||
@@ -159,0 +165,0 @@ |
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
102811
1.8%1342
4.6%174
3.57%