UNPKG

5.72 kBTypeScriptView Raw
1import * as ts from 'typescript';
2import { SymbolDisplayPart } from 'typescript';
3export interface StringIndexedObject<T> {
4 [key: string]: T;
5}
6export interface ComponentDoc {
7 expression?: ts.Symbol;
8 displayName: string;
9 filePath: string;
10 description: string;
11 props: Props;
12 methods: Method[];
13 tags?: StringIndexedObject<string>;
14}
15export interface Props extends StringIndexedObject<PropItem> {
16}
17export interface PropItem {
18 name: string;
19 required: boolean;
20 type: PropItemType;
21 description: string;
22 defaultValue: any;
23 parent?: ParentType;
24 declarations?: ParentType[];
25 tags?: {};
26}
27export interface Method {
28 name: string;
29 docblock: string;
30 modifiers: string[];
31 params: MethodParameter[];
32 returns?: {
33 description?: string | null;
34 type?: string;
35 } | null;
36 description: string;
37}
38export interface MethodParameter {
39 name: string;
40 description?: string | null;
41 type: MethodParameterType;
42}
43export interface MethodParameterType {
44 name: string;
45}
46export interface Component {
47 name: string;
48}
49export interface PropItemType {
50 name: string;
51 value?: any;
52 raw?: string;
53}
54export interface ParentType {
55 name: string;
56 fileName: string;
57}
58export declare type PropFilter = (props: PropItem, component: Component) => boolean;
59export declare type ComponentNameResolver = (exp: ts.Symbol, source: ts.SourceFile) => string | undefined | null | false;
60export interface ParserOptions {
61 propFilter?: StaticPropFilter | PropFilter;
62 componentNameResolver?: ComponentNameResolver;
63 shouldExtractLiteralValuesFromEnum?: boolean;
64 shouldRemoveUndefinedFromOptional?: boolean;
65 shouldExtractValuesFromUnion?: boolean;
66 skipChildrenPropWithoutDoc?: boolean;
67 savePropValueAsString?: boolean;
68 shouldIncludePropTagMap?: boolean;
69 shouldIncludeExpression?: boolean;
70 customComponentTypes?: string[];
71}
72export interface StaticPropFilter {
73 skipPropsWithName?: string[] | string;
74 skipPropsWithoutDoc?: boolean;
75}
76export declare const defaultParserOpts: ParserOptions;
77export interface FileParser {
78 parse(filePathOrPaths: string | string[]): ComponentDoc[];
79 parseWithProgramProvider(filePathOrPaths: string | string[], programProvider?: () => ts.Program): ComponentDoc[];
80}
81export declare const defaultOptions: ts.CompilerOptions;
82/**
83 * Parses a file with default TS options
84 * @param filePathOrPaths component file that should be parsed
85 * @param parserOpts options used to parse the files
86 */
87export declare function parse(filePathOrPaths: string | string[], parserOpts?: ParserOptions): ComponentDoc[];
88/**
89 * Constructs a parser for a default configuration.
90 */
91export declare function withDefaultConfig(parserOpts?: ParserOptions): FileParser;
92/**
93 * Constructs a parser for a specified tsconfig file.
94 */
95export declare function withCustomConfig(tsconfigPath: string, parserOpts: ParserOptions): FileParser;
96/**
97 * Constructs a parser for a specified set of TS compiler options.
98 */
99export declare function withCompilerOptions(compilerOptions: ts.CompilerOptions, parserOpts?: ParserOptions): FileParser;
100interface JSDoc {
101 description: string;
102 fullComment: string;
103 tags: StringIndexedObject<string>;
104}
105export declare class Parser {
106 private readonly checker;
107 private readonly propFilter;
108 private readonly shouldRemoveUndefinedFromOptional;
109 private readonly shouldExtractLiteralValuesFromEnum;
110 private readonly shouldExtractValuesFromUnion;
111 private readonly savePropValueAsString;
112 private readonly shouldIncludePropTagMap;
113 private readonly shouldIncludeExpression;
114 constructor(program: ts.Program, opts: ParserOptions);
115 private getComponentFromExpression;
116 getComponentInfo(exp: ts.Symbol, source: ts.SourceFile, componentNameResolver?: ComponentNameResolver, customComponentTypes?: ParserOptions['customComponentTypes']): ComponentDoc | null;
117 extractPropsFromTypeIfStatelessComponent(type: ts.Type): ts.Symbol | null;
118 extractPropsFromTypeIfStatefulComponent(type: ts.Type): ts.Symbol | null;
119 extractMembersFromType(type: ts.Type): ts.Symbol[];
120 getMethodsInfo(type: ts.Type): Method[];
121 getModifiers(member: ts.Symbol): string[];
122 getParameterInfo(callSignature: ts.Signature): MethodParameter[];
123 getCallSignature(symbol: ts.Symbol): ts.Signature;
124 isTaggedPublic(symbol: ts.Symbol): boolean;
125 getReturnDescription(symbol: ts.Symbol): SymbolDisplayPart[] | undefined;
126 private getValuesFromUnionType;
127 private getInfoFromUnionType;
128 getDocgenType(propType: ts.Type, isRequired: boolean): PropItemType;
129 getPropsInfo(propsObj: ts.Symbol, defaultProps?: StringIndexedObject<string>): Props;
130 findDocComment(symbol: ts.Symbol): JSDoc;
131 /**
132 * Extracts a full JsDoc comment from a symbol, even
133 * though TypeScript has broken down the JsDoc comment into plain
134 * text and JsDoc tags.
135 */
136 getFullJsDocComment(symbol: ts.Symbol): JSDoc;
137 getFunctionStatement(statement: ts.Statement): ts.ArrowFunction | ts.FunctionExpression | ts.FunctionDeclaration | undefined;
138 extractDefaultPropsFromComponent(symbol: ts.Symbol, source: ts.SourceFile): {};
139 getLiteralValueFromImportSpecifier(property: ts.ImportSpecifier): string | boolean | number | null | undefined;
140 getLiteralValueFromPropertyAssignment(property: ts.PropertyAssignment | ts.BindingElement): string | boolean | number | null | undefined;
141 getPropMap(properties: ts.NodeArray<ts.PropertyAssignment | ts.BindingElement>): StringIndexedObject<string | boolean | number | null>;
142}
143export declare function getDefaultExportForFile(source: ts.SourceFile): string;
144export {};