1 | import * as ts from 'typescript';
|
2 | import { SymbolDisplayPart } from 'typescript';
|
3 | export interface StringIndexedObject<T> {
|
4 | [key: string]: T;
|
5 | }
|
6 | export 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 | }
|
15 | export interface Props extends StringIndexedObject<PropItem> {
|
16 | }
|
17 | export 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 | }
|
27 | export 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 | }
|
38 | export interface MethodParameter {
|
39 | name: string;
|
40 | description?: string | null;
|
41 | type: MethodParameterType;
|
42 | }
|
43 | export interface MethodParameterType {
|
44 | name: string;
|
45 | }
|
46 | export interface Component {
|
47 | name: string;
|
48 | }
|
49 | export interface PropItemType {
|
50 | name: string;
|
51 | value?: any;
|
52 | raw?: string;
|
53 | }
|
54 | export interface ParentType {
|
55 | name: string;
|
56 | fileName: string;
|
57 | }
|
58 | export declare type PropFilter = (props: PropItem, component: Component) => boolean;
|
59 | export declare type ComponentNameResolver = (exp: ts.Symbol, source: ts.SourceFile) => string | undefined | null | false;
|
60 | export 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 | }
|
72 | export interface StaticPropFilter {
|
73 | skipPropsWithName?: string[] | string;
|
74 | skipPropsWithoutDoc?: boolean;
|
75 | }
|
76 | export declare const defaultParserOpts: ParserOptions;
|
77 | export interface FileParser {
|
78 | parse(filePathOrPaths: string | string[]): ComponentDoc[];
|
79 | parseWithProgramProvider(filePathOrPaths: string | string[], programProvider?: () => ts.Program): ComponentDoc[];
|
80 | }
|
81 | export declare const defaultOptions: ts.CompilerOptions;
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | export declare function parse(filePathOrPaths: string | string[], parserOpts?: ParserOptions): ComponentDoc[];
|
88 |
|
89 |
|
90 |
|
91 | export declare function withDefaultConfig(parserOpts?: ParserOptions): FileParser;
|
92 |
|
93 |
|
94 |
|
95 | export declare function withCustomConfig(tsconfigPath: string, parserOpts: ParserOptions): FileParser;
|
96 |
|
97 |
|
98 |
|
99 | export declare function withCompilerOptions(compilerOptions: ts.CompilerOptions, parserOpts?: ParserOptions): FileParser;
|
100 | interface JSDoc {
|
101 | description: string;
|
102 | fullComment: string;
|
103 | tags: StringIndexedObject<string>;
|
104 | }
|
105 | export 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 | }
|
143 | export declare function getDefaultExportForFile(source: ts.SourceFile): string;
|
144 | export {};
|