@vev/silke 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.js +22 -22
- package/dist/types/components/silke-conditions-input/utils.d.ts +1 -1
- package/dist/types/components/silke-form-schema/fields/audio-field.d.ts +3 -0
- package/dist/types/components/silke-gradient-picker/silke-gradient-picker.d.ts +2 -5
- package/dist/types/icons.d.ts +7 -0
- package/jest.config.js +1 -0
- package/package.json +3 -27
- package/project.json +0 -9
- package/src/components/silke-autocomplete-field/autocomplete-item.tsx +1 -0
- package/src/components/silke-card/silke-card.tsx +12 -1
- package/src/components/silke-css-number-field/silke-css-number-field.tsx +2 -1
- package/src/components/silke-form-schema/fields/audio-field.tsx +77 -0
- package/src/components/silke-form-schema/fields/select-field.tsx +1 -1
- package/src/components/silke-form-schema/silke-schema-field.tsx +2 -3
- package/src/components/silke-gradient-picker/silke-gradient-picker.tsx +33 -16
- package/src/components/silke-icon-picker/icons-tab.tsx +1 -1
- package/src/icons.tsx +44 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/docs/app.d.ts +0 -3
- package/dist/types/docs/components/code-block/code-block.d.ts +0 -5
- package/dist/types/docs/components/code-block/index.d.ts +0 -1
- package/dist/types/docs/components/state-table/index.d.ts +0 -1
- package/dist/types/docs/components/state-table/state-table.d.ts +0 -13
- package/dist/types/docs/data/app/actions.d.ts +0 -1
- package/dist/types/docs/data/app/constants.d.ts +0 -5
- package/dist/types/docs/data/app/index.d.ts +0 -3
- package/dist/types/docs/data/app/store.d.ts +0 -8
- package/dist/types/docs/data/flux/action-decorator.d.ts +0 -5
- package/dist/types/docs/data/flux/action-utils.d.ts +0 -7
- package/dist/types/docs/data/flux/controller.d.ts +0 -24
- package/dist/types/docs/data/flux/dispatcher.d.ts +0 -7
- package/dist/types/docs/data/flux/index.d.ts +0 -6
- package/dist/types/docs/data/flux/store.d.ts +0 -15
- package/dist/types/docs/data/flux/use-store.d.ts +0 -2
- package/dist/types/docs/docs-provider.d.ts +0 -6
- package/dist/types/docs/index.d.ts +0 -2
- package/dist/types/docs/ipsum-generator.d.ts +0 -7
- package/dist/types/docs/parser.d.ts +0 -0
- package/dist/types/main.d.ts +0 -1
- package/public/index.html +0 -23
- package/src/docs/app.tsx +0 -166
- package/src/docs/components/code-block/code-block.scss +0 -15
- package/src/docs/components/code-block/code-block.tsx +0 -55
- package/src/docs/components/code-block/index.ts +0 -1
- package/src/docs/components/state-table/index.ts +0 -1
- package/src/docs/components/state-table/state-table.scss +0 -10
- package/src/docs/components/state-table/state-table.tsx +0 -57
- package/src/docs/data/app/actions.ts +0 -17
- package/src/docs/data/app/constants.ts +0 -5
- package/src/docs/data/app/index.ts +0 -3
- package/src/docs/data/app/store.ts +0 -14
- package/src/docs/data/flux/action-decorator.ts +0 -16
- package/src/docs/data/flux/action-utils.ts +0 -19
- package/src/docs/data/flux/controller.ts +0 -76
- package/src/docs/data/flux/dispatcher.ts +0 -79
- package/src/docs/data/flux/index.ts +0 -10
- package/src/docs/data/flux/store.ts +0 -44
- package/src/docs/data/flux/use-store.ts +0 -57
- package/src/docs/docs-provider.tsx +0 -24
- package/src/docs/index.ts +0 -3
- package/src/docs/ipsum-generator.tsx +0 -86
- package/src/docs/parser.ts +0 -1345
- package/src/index.mdx +0 -69
- package/src/main.tsx +0 -11
- package/src/playground.mdx +0 -65
- package/webpack.docs.ts +0 -248
package/src/docs/parser.ts
DELETED
|
@@ -1,1345 +0,0 @@
|
|
|
1
|
-
// import ts from 'typescript';
|
|
2
|
-
|
|
3
|
-
// function buildFilter(opts: ParserOptions): PropFilter {
|
|
4
|
-
// return (prop: PropItem, component: Component) => {
|
|
5
|
-
// const { propFilter } = opts;
|
|
6
|
-
// // skip children property in case it has no custom documentation
|
|
7
|
-
// if (
|
|
8
|
-
// prop.name === 'children' &&
|
|
9
|
-
// prop.description.length === 0 &&
|
|
10
|
-
// opts.skipChildrenPropWithoutDoc !== false
|
|
11
|
-
// ) {
|
|
12
|
-
// return false;
|
|
13
|
-
// }
|
|
14
|
-
// if (typeof propFilter === 'function') {
|
|
15
|
-
// const keep = propFilter(prop, component);
|
|
16
|
-
// if (!keep) {
|
|
17
|
-
// return false;
|
|
18
|
-
// }
|
|
19
|
-
// } else if (typeof propFilter === 'object') {
|
|
20
|
-
// const {
|
|
21
|
-
// skipPropsWithName,
|
|
22
|
-
// skipPropsWithoutDoc
|
|
23
|
-
// } = propFilter as StaticPropFilter;
|
|
24
|
-
// if (
|
|
25
|
-
// typeof skipPropsWithName === 'string' &&
|
|
26
|
-
// skipPropsWithName === prop.name
|
|
27
|
-
// ) {
|
|
28
|
-
// return false;
|
|
29
|
-
// } else if (
|
|
30
|
-
// Array.isArray(skipPropsWithName) &&
|
|
31
|
-
// skipPropsWithName.indexOf(prop.name) > -1
|
|
32
|
-
// ) {
|
|
33
|
-
// return false;
|
|
34
|
-
// }
|
|
35
|
-
// if (skipPropsWithoutDoc && prop.description.length === 0) {
|
|
36
|
-
// return false;
|
|
37
|
-
// }
|
|
38
|
-
// }
|
|
39
|
-
// return true;
|
|
40
|
-
// };
|
|
41
|
-
// }
|
|
42
|
-
|
|
43
|
-
// // We'll use the currentDirectoryName to trim parent fileNames
|
|
44
|
-
// const currentDirectoryPath = process.cwd();
|
|
45
|
-
// const currentDirectoryParts = currentDirectoryPath.split(path.sep);
|
|
46
|
-
// const currentDirectoryName =
|
|
47
|
-
// currentDirectoryParts[currentDirectoryParts.length - 1];
|
|
48
|
-
|
|
49
|
-
// type InterfaceOrTypeAliasDeclaration =
|
|
50
|
-
// | ts.TypeAliasDeclaration
|
|
51
|
-
// | ts.InterfaceDeclaration;
|
|
52
|
-
// export interface StringIndexedObject<T> {
|
|
53
|
-
// [key: string]: T;
|
|
54
|
-
// }
|
|
55
|
-
|
|
56
|
-
// export interface ComponentDoc {
|
|
57
|
-
// displayName: string;
|
|
58
|
-
// description: string;
|
|
59
|
-
// props: Props;
|
|
60
|
-
// methods: Method[];
|
|
61
|
-
// tags?: {};
|
|
62
|
-
// }
|
|
63
|
-
|
|
64
|
-
// export interface Props extends StringIndexedObject<PropItem> {}
|
|
65
|
-
|
|
66
|
-
// export interface PropItem {
|
|
67
|
-
// name: string;
|
|
68
|
-
// required: boolean;
|
|
69
|
-
// type: PropItemType;
|
|
70
|
-
// description: string;
|
|
71
|
-
// defaultValue: any;
|
|
72
|
-
// parent?: ParentType;
|
|
73
|
-
// declarations?: ParentType[];
|
|
74
|
-
// }
|
|
75
|
-
|
|
76
|
-
// export interface Method {
|
|
77
|
-
// name: string;
|
|
78
|
-
// docblock: string;
|
|
79
|
-
// modifiers: string[];
|
|
80
|
-
// params: MethodParameter[];
|
|
81
|
-
// returns?: {
|
|
82
|
-
// description?: string | null;
|
|
83
|
-
// type?: string;
|
|
84
|
-
// } | null;
|
|
85
|
-
// description: string;
|
|
86
|
-
// }
|
|
87
|
-
|
|
88
|
-
// export interface MethodParameter {
|
|
89
|
-
// name: string;
|
|
90
|
-
// description?: string | null;
|
|
91
|
-
// type: MethodParameterType;
|
|
92
|
-
// }
|
|
93
|
-
|
|
94
|
-
// export interface MethodParameterType {
|
|
95
|
-
// name: string;
|
|
96
|
-
// }
|
|
97
|
-
|
|
98
|
-
// export interface Component {
|
|
99
|
-
// name: string;
|
|
100
|
-
// }
|
|
101
|
-
|
|
102
|
-
// export interface PropItemType {
|
|
103
|
-
// name: string;
|
|
104
|
-
// value?: any;
|
|
105
|
-
// raw?: string;
|
|
106
|
-
// }
|
|
107
|
-
|
|
108
|
-
// export interface ParentType {
|
|
109
|
-
// name: string;
|
|
110
|
-
// fileName: string;
|
|
111
|
-
// }
|
|
112
|
-
|
|
113
|
-
// export type PropFilter = (props: PropItem, component: Component) => boolean;
|
|
114
|
-
|
|
115
|
-
// export type ComponentNameResolver = (
|
|
116
|
-
// exp: ts.Symbol,
|
|
117
|
-
// source: ts.SourceFile
|
|
118
|
-
// ) => string | undefined | null | false;
|
|
119
|
-
|
|
120
|
-
// export interface ParserOptions {
|
|
121
|
-
// propFilter?: StaticPropFilter | PropFilter;
|
|
122
|
-
// componentNameResolver?: ComponentNameResolver;
|
|
123
|
-
// shouldExtractLiteralValuesFromEnum?: boolean;
|
|
124
|
-
// shouldRemoveUndefinedFromOptional?: boolean;
|
|
125
|
-
// shouldExtractValuesFromUnion?: boolean;
|
|
126
|
-
// skipChildrenPropWithoutDoc?: boolean;
|
|
127
|
-
// savePropValueAsString?: boolean;
|
|
128
|
-
// }
|
|
129
|
-
|
|
130
|
-
// export interface StaticPropFilter {
|
|
131
|
-
// skipPropsWithName?: string[] | string;
|
|
132
|
-
// skipPropsWithoutDoc?: boolean;
|
|
133
|
-
// }
|
|
134
|
-
|
|
135
|
-
// export const defaultParserOpts: ParserOptions = {};
|
|
136
|
-
|
|
137
|
-
// export interface FileParser {
|
|
138
|
-
// parse(filePathOrPaths: string | string[]): ComponentDoc[];
|
|
139
|
-
// parseWithProgramProvider(
|
|
140
|
-
// filePathOrPaths: string | string[],
|
|
141
|
-
// programProvider?: () => ts.Program
|
|
142
|
-
// ): ComponentDoc[];
|
|
143
|
-
// }
|
|
144
|
-
|
|
145
|
-
// export const defaultOptions: ts.CompilerOptions = {
|
|
146
|
-
// jsx: ts.JsxEmit.React,
|
|
147
|
-
// module: ts.ModuleKind.CommonJS,
|
|
148
|
-
// target: ts.ScriptTarget.Latest
|
|
149
|
-
// };
|
|
150
|
-
|
|
151
|
-
// /**
|
|
152
|
-
// * Parses a file with default TS options
|
|
153
|
-
// * @param filePath component file that should be parsed
|
|
154
|
-
// */
|
|
155
|
-
// export function parse(
|
|
156
|
-
// filePathOrPaths: string | string[],
|
|
157
|
-
// parserOpts: ParserOptions = defaultParserOpts
|
|
158
|
-
// ) {
|
|
159
|
-
// return withCompilerOptions(defaultOptions, parserOpts).parse(filePathOrPaths);
|
|
160
|
-
// }
|
|
161
|
-
|
|
162
|
-
// /**
|
|
163
|
-
// * Constructs a parser for a default configuration.
|
|
164
|
-
// */
|
|
165
|
-
// export function withDefaultConfig(
|
|
166
|
-
// parserOpts: ParserOptions = defaultParserOpts
|
|
167
|
-
// ): FileParser {
|
|
168
|
-
// return withCompilerOptions(defaultOptions, parserOpts);
|
|
169
|
-
// }
|
|
170
|
-
|
|
171
|
-
// /**
|
|
172
|
-
// * Constructs a parser for a specified set of TS compiler options.
|
|
173
|
-
// */
|
|
174
|
-
// export function withCompilerOptions(
|
|
175
|
-
// compilerOptions: ts.CompilerOptions,
|
|
176
|
-
// parserOpts: ParserOptions = defaultParserOpts
|
|
177
|
-
// ): FileParser {
|
|
178
|
-
// return {
|
|
179
|
-
// parse(filePathOrPaths: string | string[]): ComponentDoc[] {
|
|
180
|
-
// return parseWithProgramProvider(
|
|
181
|
-
// filePathOrPaths,
|
|
182
|
-
// compilerOptions,
|
|
183
|
-
// parserOpts
|
|
184
|
-
// );
|
|
185
|
-
// },
|
|
186
|
-
// parseWithProgramProvider(filePathOrPaths, programProvider) {
|
|
187
|
-
// return parseWithProgramProvider(
|
|
188
|
-
// filePathOrPaths,
|
|
189
|
-
// compilerOptions,
|
|
190
|
-
// parserOpts,
|
|
191
|
-
// programProvider
|
|
192
|
-
// );
|
|
193
|
-
// }
|
|
194
|
-
// };
|
|
195
|
-
// }
|
|
196
|
-
|
|
197
|
-
// const isOptional = (prop: ts.Symbol) =>
|
|
198
|
-
// // tslint:disable-next-line:no-bitwise
|
|
199
|
-
// (prop.getFlags() & ts.SymbolFlags.Optional) !== 0;
|
|
200
|
-
|
|
201
|
-
// interface JSDoc {
|
|
202
|
-
// description: string;
|
|
203
|
-
// fullComment: string;
|
|
204
|
-
// tags: StringIndexedObject<string>;
|
|
205
|
-
// }
|
|
206
|
-
|
|
207
|
-
// const defaultJSDoc: JSDoc = {
|
|
208
|
-
// description: '',
|
|
209
|
-
// fullComment: '',
|
|
210
|
-
// tags: {}
|
|
211
|
-
// };
|
|
212
|
-
|
|
213
|
-
// export class Parser {
|
|
214
|
-
// private checker: ts.TypeChecker;
|
|
215
|
-
// private propFilter: PropFilter;
|
|
216
|
-
// private shouldRemoveUndefinedFromOptional: boolean;
|
|
217
|
-
// private shouldExtractLiteralValuesFromEnum: boolean;
|
|
218
|
-
// private shouldExtractValuesFromUnion: boolean;
|
|
219
|
-
// private savePropValueAsString: boolean;
|
|
220
|
-
|
|
221
|
-
// constructor(program: ts.Program, opts: ParserOptions) {
|
|
222
|
-
// const {
|
|
223
|
-
// savePropValueAsString,
|
|
224
|
-
// shouldExtractLiteralValuesFromEnum,
|
|
225
|
-
// shouldRemoveUndefinedFromOptional,
|
|
226
|
-
// shouldExtractValuesFromUnion
|
|
227
|
-
// } = opts;
|
|
228
|
-
// this.checker = program.getTypeChecker();
|
|
229
|
-
// this.propFilter = buildFilter(opts);
|
|
230
|
-
// this.shouldExtractLiteralValuesFromEnum = Boolean(
|
|
231
|
-
// shouldExtractLiteralValuesFromEnum
|
|
232
|
-
// );
|
|
233
|
-
// this.shouldRemoveUndefinedFromOptional = Boolean(
|
|
234
|
-
// shouldRemoveUndefinedFromOptional
|
|
235
|
-
// );
|
|
236
|
-
// this.shouldExtractValuesFromUnion = Boolean(shouldExtractValuesFromUnion);
|
|
237
|
-
// this.savePropValueAsString = Boolean(savePropValueAsString);
|
|
238
|
-
// }
|
|
239
|
-
|
|
240
|
-
// private getComponentFromExpression(exp: ts.Symbol) {
|
|
241
|
-
// const declaration = exp.valueDeclaration || exp.declarations![0];
|
|
242
|
-
// const type = this.checker.getTypeOfSymbolAtLocation(exp, declaration);
|
|
243
|
-
// const typeSymbol = type.symbol || type.aliasSymbol;
|
|
244
|
-
|
|
245
|
-
// if (!typeSymbol) {
|
|
246
|
-
// return exp;
|
|
247
|
-
// }
|
|
248
|
-
|
|
249
|
-
// const symbolName = typeSymbol.getName();
|
|
250
|
-
|
|
251
|
-
// if (
|
|
252
|
-
// (symbolName === 'MemoExoticComponent' ||
|
|
253
|
-
// symbolName === 'ForwardRefExoticComponent') &&
|
|
254
|
-
// exp.valueDeclaration &&
|
|
255
|
-
// ts.isExportAssignment(exp.valueDeclaration) &&
|
|
256
|
-
// ts.isCallExpression(exp.valueDeclaration.expression)
|
|
257
|
-
// ) {
|
|
258
|
-
// const component = this.checker.getSymbolAtLocation(
|
|
259
|
-
// exp.valueDeclaration.expression.arguments[0]
|
|
260
|
-
// );
|
|
261
|
-
|
|
262
|
-
// if (component) {
|
|
263
|
-
// exp = component;
|
|
264
|
-
// }
|
|
265
|
-
// }
|
|
266
|
-
|
|
267
|
-
// return exp;
|
|
268
|
-
// }
|
|
269
|
-
|
|
270
|
-
// public getComponentInfo(
|
|
271
|
-
// exp: ts.Symbol,
|
|
272
|
-
// source: ts.SourceFile,
|
|
273
|
-
// componentNameResolver: ComponentNameResolver = () => undefined
|
|
274
|
-
// ): ComponentDoc | null {
|
|
275
|
-
// if (!!exp.declarations && exp.declarations.length === 0) {
|
|
276
|
-
// return null;
|
|
277
|
-
// }
|
|
278
|
-
|
|
279
|
-
// let rootExp = this.getComponentFromExpression(exp);
|
|
280
|
-
// const declaration = rootExp.valueDeclaration || rootExp.declarations![0];
|
|
281
|
-
// const type = this.checker.getTypeOfSymbolAtLocation(rootExp, declaration);
|
|
282
|
-
|
|
283
|
-
// let commentSource = rootExp;
|
|
284
|
-
// const typeSymbol = type.symbol || type.aliasSymbol;
|
|
285
|
-
// const originalName = rootExp.getName();
|
|
286
|
-
|
|
287
|
-
// if (!rootExp.valueDeclaration) {
|
|
288
|
-
// if (
|
|
289
|
-
// originalName === 'default' &&
|
|
290
|
-
// !typeSymbol &&
|
|
291
|
-
// (rootExp.flags & ts.SymbolFlags.Alias) !== 0
|
|
292
|
-
// ) {
|
|
293
|
-
// commentSource = this.checker.getAliasedSymbol(commentSource);
|
|
294
|
-
// } else if (!typeSymbol) {
|
|
295
|
-
// return null;
|
|
296
|
-
// } else {
|
|
297
|
-
// rootExp = typeSymbol;
|
|
298
|
-
// const expName = rootExp.getName();
|
|
299
|
-
|
|
300
|
-
// if (
|
|
301
|
-
// expName === '__function' ||
|
|
302
|
-
// expName === 'StatelessComponent' ||
|
|
303
|
-
// expName === 'Stateless' ||
|
|
304
|
-
// expName === 'StyledComponentClass' ||
|
|
305
|
-
// expName === 'StyledComponent' ||
|
|
306
|
-
// expName === 'FunctionComponent' ||
|
|
307
|
-
// expName === 'ForwardRefExoticComponent'
|
|
308
|
-
// ) {
|
|
309
|
-
// commentSource = this.checker.getAliasedSymbol(commentSource);
|
|
310
|
-
// } else {
|
|
311
|
-
// commentSource = rootExp;
|
|
312
|
-
// }
|
|
313
|
-
// }
|
|
314
|
-
// } else if (
|
|
315
|
-
// type.symbol &&
|
|
316
|
-
// (ts.isPropertyAccessExpression(declaration) ||
|
|
317
|
-
// ts.isPropertyDeclaration(declaration))
|
|
318
|
-
// ) {
|
|
319
|
-
// commentSource = type.symbol;
|
|
320
|
-
// }
|
|
321
|
-
|
|
322
|
-
// // Skip over PropTypes that are exported
|
|
323
|
-
// if (
|
|
324
|
-
// typeSymbol &&
|
|
325
|
-
// (typeSymbol.getEscapedName() === 'Requireable' ||
|
|
326
|
-
// typeSymbol.getEscapedName() === 'Validator')
|
|
327
|
-
// ) {
|
|
328
|
-
// return null;
|
|
329
|
-
// }
|
|
330
|
-
|
|
331
|
-
// const propsType =
|
|
332
|
-
// this.extractPropsFromTypeIfStatelessComponent(type) ||
|
|
333
|
-
// this.extractPropsFromTypeIfStatefulComponent(type);
|
|
334
|
-
|
|
335
|
-
// const nameSource = originalName === 'default' ? rootExp : commentSource;
|
|
336
|
-
// const resolvedComponentName = componentNameResolver(nameSource, source);
|
|
337
|
-
// const { description, tags } = this.findDocComment(commentSource);
|
|
338
|
-
// const displayName =
|
|
339
|
-
// resolvedComponentName ||
|
|
340
|
-
// tags.visibleName ||
|
|
341
|
-
// computeComponentName(nameSource, source);
|
|
342
|
-
// const methods = this.getMethodsInfo(type);
|
|
343
|
-
|
|
344
|
-
// if (propsType) {
|
|
345
|
-
// if (!commentSource.valueDeclaration) {
|
|
346
|
-
// return null;
|
|
347
|
-
// }
|
|
348
|
-
// const defaultProps = this.extractDefaultPropsFromComponent(
|
|
349
|
-
// commentSource,
|
|
350
|
-
// commentSource.valueDeclaration.getSourceFile()
|
|
351
|
-
// );
|
|
352
|
-
// const props = this.getPropsInfo(propsType, defaultProps);
|
|
353
|
-
|
|
354
|
-
// for (const propName of Object.keys(props)) {
|
|
355
|
-
// const prop = props[propName];
|
|
356
|
-
// const component: Component = { name: displayName };
|
|
357
|
-
// if (!this.propFilter(prop, component)) {
|
|
358
|
-
// delete props[propName];
|
|
359
|
-
// }
|
|
360
|
-
// }
|
|
361
|
-
// return {
|
|
362
|
-
// tags,
|
|
363
|
-
// description,
|
|
364
|
-
// displayName,
|
|
365
|
-
// methods,
|
|
366
|
-
// props
|
|
367
|
-
// };
|
|
368
|
-
// } else if (description && displayName) {
|
|
369
|
-
// return {
|
|
370
|
-
// tags,
|
|
371
|
-
// description,
|
|
372
|
-
// displayName,
|
|
373
|
-
// methods,
|
|
374
|
-
// props: {}
|
|
375
|
-
// };
|
|
376
|
-
// }
|
|
377
|
-
|
|
378
|
-
// return null;
|
|
379
|
-
// }
|
|
380
|
-
|
|
381
|
-
// public extractPropsFromTypeIfStatelessComponent(
|
|
382
|
-
// type: ts.Type
|
|
383
|
-
// ): ts.Symbol | null {
|
|
384
|
-
// const callSignatures = type.getCallSignatures();
|
|
385
|
-
|
|
386
|
-
// if (callSignatures.length) {
|
|
387
|
-
// // Could be a stateless component. Is a function, so the props object we're interested
|
|
388
|
-
// // in is the (only) parameter.
|
|
389
|
-
|
|
390
|
-
// for (const sig of callSignatures) {
|
|
391
|
-
// const params = sig.getParameters();
|
|
392
|
-
// if (params.length === 0) {
|
|
393
|
-
// continue;
|
|
394
|
-
// }
|
|
395
|
-
// // Maybe we could check return type instead,
|
|
396
|
-
// // but not sure if Element, ReactElement<T> are all possible values
|
|
397
|
-
// const propsParam = params[0];
|
|
398
|
-
// if (propsParam.name === 'props' || params.length === 1) {
|
|
399
|
-
// return propsParam;
|
|
400
|
-
// }
|
|
401
|
-
// }
|
|
402
|
-
// }
|
|
403
|
-
|
|
404
|
-
// return null;
|
|
405
|
-
// }
|
|
406
|
-
|
|
407
|
-
// public extractPropsFromTypeIfStatefulComponent(
|
|
408
|
-
// type: ts.Type
|
|
409
|
-
// ): ts.Symbol | null {
|
|
410
|
-
// const constructSignatures = type.getConstructSignatures();
|
|
411
|
-
|
|
412
|
-
// if (constructSignatures.length) {
|
|
413
|
-
// // React.Component. Is a class, so the props object we're interested
|
|
414
|
-
// // in is the type of 'props' property of the object constructed by the class.
|
|
415
|
-
|
|
416
|
-
// for (const sig of constructSignatures) {
|
|
417
|
-
// const instanceType = sig.getReturnType();
|
|
418
|
-
// const props = instanceType.getProperty('props');
|
|
419
|
-
|
|
420
|
-
// if (props) {
|
|
421
|
-
// return props;
|
|
422
|
-
// }
|
|
423
|
-
// }
|
|
424
|
-
// }
|
|
425
|
-
|
|
426
|
-
// return null;
|
|
427
|
-
// }
|
|
428
|
-
|
|
429
|
-
// public extractMembersFromType(type: ts.Type): ts.Symbol[] {
|
|
430
|
-
// const methodSymbols: ts.Symbol[] = [];
|
|
431
|
-
|
|
432
|
-
// /**
|
|
433
|
-
// * Need to loop over properties first so we capture any
|
|
434
|
-
// * static methods. static methods aren't captured in type.symbol.members
|
|
435
|
-
// */
|
|
436
|
-
// type.getProperties().forEach(property => {
|
|
437
|
-
// // Only add members, don't add non-member properties
|
|
438
|
-
// if (this.getCallSignature(property)) {
|
|
439
|
-
// methodSymbols.push(property);
|
|
440
|
-
// }
|
|
441
|
-
// });
|
|
442
|
-
|
|
443
|
-
// if (type.symbol && type.symbol.members) {
|
|
444
|
-
// type.symbol.members.forEach(member => {
|
|
445
|
-
// methodSymbols.push(member);
|
|
446
|
-
// });
|
|
447
|
-
// }
|
|
448
|
-
|
|
449
|
-
// return methodSymbols;
|
|
450
|
-
// }
|
|
451
|
-
|
|
452
|
-
// public getMethodsInfo(type: ts.Type): Method[] {
|
|
453
|
-
// const members = this.extractMembersFromType(type);
|
|
454
|
-
// const methods: Method[] = [];
|
|
455
|
-
// members.forEach(member => {
|
|
456
|
-
// if (!this.isTaggedPublic(member)) {
|
|
457
|
-
// return;
|
|
458
|
-
// }
|
|
459
|
-
|
|
460
|
-
// const name = member.getName();
|
|
461
|
-
// const docblock = this.getFullJsDocComment(member).fullComment;
|
|
462
|
-
// const callSignature = this.getCallSignature(member);
|
|
463
|
-
// const params = this.getParameterInfo(callSignature);
|
|
464
|
-
// const description = ts.displayPartsToString(
|
|
465
|
-
// member.getDocumentationComment(this.checker)
|
|
466
|
-
// );
|
|
467
|
-
// const returnType = this.checker.typeToString(
|
|
468
|
-
// callSignature.getReturnType()
|
|
469
|
-
// );
|
|
470
|
-
// const returnDescription = this.getReturnDescription(member);
|
|
471
|
-
// const modifiers = this.getModifiers(member);
|
|
472
|
-
|
|
473
|
-
// methods.push({
|
|
474
|
-
// description,
|
|
475
|
-
// docblock,
|
|
476
|
-
// modifiers,
|
|
477
|
-
// name,
|
|
478
|
-
// params,
|
|
479
|
-
// returns: returnDescription
|
|
480
|
-
// ? {
|
|
481
|
-
// description: returnDescription,
|
|
482
|
-
// type: returnType
|
|
483
|
-
// }
|
|
484
|
-
// : null
|
|
485
|
-
// });
|
|
486
|
-
// });
|
|
487
|
-
|
|
488
|
-
// return methods;
|
|
489
|
-
// }
|
|
490
|
-
|
|
491
|
-
// public getModifiers(member: ts.Symbol) {
|
|
492
|
-
// const modifiers: string[] = [];
|
|
493
|
-
// const flags = ts.getCombinedModifierFlags(member.valueDeclaration);
|
|
494
|
-
// const isStatic = (flags & ts.ModifierFlags.Static) !== 0; // tslint:disable-line no-bitwise
|
|
495
|
-
|
|
496
|
-
// if (isStatic) {
|
|
497
|
-
// modifiers.push('static');
|
|
498
|
-
// }
|
|
499
|
-
|
|
500
|
-
// return modifiers;
|
|
501
|
-
// }
|
|
502
|
-
|
|
503
|
-
// public getParameterInfo(callSignature: ts.Signature): MethodParameter[] {
|
|
504
|
-
// return callSignature.parameters.map(param => {
|
|
505
|
-
// const paramType = this.checker.getTypeOfSymbolAtLocation(
|
|
506
|
-
// param,
|
|
507
|
-
// param.valueDeclaration
|
|
508
|
-
// );
|
|
509
|
-
// const paramDeclaration = this.checker.symbolToParameterDeclaration(param);
|
|
510
|
-
// const isOptionalParam: boolean = !!(
|
|
511
|
-
// paramDeclaration && paramDeclaration.questionToken
|
|
512
|
-
// );
|
|
513
|
-
|
|
514
|
-
// return {
|
|
515
|
-
// description:
|
|
516
|
-
// ts.displayPartsToString(
|
|
517
|
-
// param.getDocumentationComment(this.checker)
|
|
518
|
-
// ) || null,
|
|
519
|
-
// name: param.getName() + (isOptionalParam ? '?' : ''),
|
|
520
|
-
// type: { name: this.checker.typeToString(paramType) }
|
|
521
|
-
// };
|
|
522
|
-
// });
|
|
523
|
-
// }
|
|
524
|
-
|
|
525
|
-
// public getCallSignature(symbol: ts.Symbol) {
|
|
526
|
-
// const symbolType = this.checker.getTypeOfSymbolAtLocation(
|
|
527
|
-
// symbol,
|
|
528
|
-
// symbol.valueDeclaration!
|
|
529
|
-
// );
|
|
530
|
-
|
|
531
|
-
// return symbolType.getCallSignatures()[0];
|
|
532
|
-
// }
|
|
533
|
-
|
|
534
|
-
// public isTaggedPublic(symbol: ts.Symbol) {
|
|
535
|
-
// const jsDocTags = symbol.getJsDocTags();
|
|
536
|
-
// const isPublic = Boolean(jsDocTags.find(tag => tag.name === 'public'));
|
|
537
|
-
// return isPublic;
|
|
538
|
-
// }
|
|
539
|
-
|
|
540
|
-
// public getReturnDescription(symbol: ts.Symbol) {
|
|
541
|
-
// const tags = symbol.getJsDocTags();
|
|
542
|
-
// const returnTag = tags.find(tag => tag.name === 'returns');
|
|
543
|
-
// if (!returnTag) {
|
|
544
|
-
// return null;
|
|
545
|
-
// }
|
|
546
|
-
|
|
547
|
-
// return returnTag.text || null;
|
|
548
|
-
// }
|
|
549
|
-
|
|
550
|
-
// private getValuesFromUnionType(type: ts.Type): string | number {
|
|
551
|
-
// if (type.isStringLiteral()) return `"${type.value}"`;
|
|
552
|
-
// if (type.isNumberLiteral()) return `${type.value}`;
|
|
553
|
-
// return this.checker.typeToString(type);
|
|
554
|
-
// }
|
|
555
|
-
|
|
556
|
-
// public getDocgenType(propType: ts.Type, isRequired: boolean): PropItemType {
|
|
557
|
-
// // When we are going to process the type, we check if this type has a constraint (is a generic type with constraint)
|
|
558
|
-
// if (propType.getConstraint()) {
|
|
559
|
-
// // If so, we assing the property the type that is the constraint
|
|
560
|
-
// propType = propType.getConstraint()!;
|
|
561
|
-
// }
|
|
562
|
-
|
|
563
|
-
// let propTypeString = this.checker.typeToString(propType);
|
|
564
|
-
|
|
565
|
-
// if (propType.isUnion()) {
|
|
566
|
-
// if (this.shouldExtractValuesFromUnion) {
|
|
567
|
-
// return {
|
|
568
|
-
// name: 'enum',
|
|
569
|
-
// raw: propTypeString,
|
|
570
|
-
// value: propType.types.map(type => ({
|
|
571
|
-
// value: this.getValuesFromUnionType(type)
|
|
572
|
-
// }))
|
|
573
|
-
// };
|
|
574
|
-
// }
|
|
575
|
-
// if (
|
|
576
|
-
// this.shouldExtractLiteralValuesFromEnum &&
|
|
577
|
-
// propType.types.every(type => type.isStringLiteral())
|
|
578
|
-
// ) {
|
|
579
|
-
// return {
|
|
580
|
-
// name: 'enum',
|
|
581
|
-
// raw: propTypeString,
|
|
582
|
-
// value: propType.types.map(type => ({
|
|
583
|
-
// value: type.isStringLiteral()
|
|
584
|
-
// ? `"${type.value}"`
|
|
585
|
-
// : this.checker.typeToString(type)
|
|
586
|
-
// }))
|
|
587
|
-
// };
|
|
588
|
-
// }
|
|
589
|
-
// }
|
|
590
|
-
|
|
591
|
-
// if (this.shouldRemoveUndefinedFromOptional && !isRequired) {
|
|
592
|
-
// propTypeString = propTypeString.replace(' | undefined', '');
|
|
593
|
-
// }
|
|
594
|
-
|
|
595
|
-
// return { name: propTypeString };
|
|
596
|
-
// }
|
|
597
|
-
|
|
598
|
-
// public getPropsInfo(
|
|
599
|
-
// propsObj: ts.Symbol,
|
|
600
|
-
// defaultProps: StringIndexedObject<string> = {}
|
|
601
|
-
// ): Props {
|
|
602
|
-
// if (!propsObj.valueDeclaration) {
|
|
603
|
-
// return {};
|
|
604
|
-
// }
|
|
605
|
-
|
|
606
|
-
// const propsType = this.checker.getTypeOfSymbolAtLocation(
|
|
607
|
-
// propsObj,
|
|
608
|
-
// propsObj.valueDeclaration
|
|
609
|
-
// );
|
|
610
|
-
// const baseProps = propsType.getApparentProperties();
|
|
611
|
-
// let propertiesOfProps = baseProps;
|
|
612
|
-
|
|
613
|
-
// if (propsType.isUnionOrIntersection()) {
|
|
614
|
-
// propertiesOfProps = [
|
|
615
|
-
// // Resolve extra properties in the union/intersection
|
|
616
|
-
// ...(propertiesOfProps = (this
|
|
617
|
-
// .checker as any).getAllPossiblePropertiesOfTypes(propsType.types)),
|
|
618
|
-
// // But props we already have override those as they are already correct.
|
|
619
|
-
// ...baseProps
|
|
620
|
-
// ];
|
|
621
|
-
|
|
622
|
-
// if (!propertiesOfProps.length) {
|
|
623
|
-
// const subTypes = (this.checker as any).getAllPossiblePropertiesOfTypes(
|
|
624
|
-
// propsType.types.reduce<ts.Symbol[]>(
|
|
625
|
-
// // @ts-ignore
|
|
626
|
-
// (all, t) => [...all, ...(t.types || [])],
|
|
627
|
-
// []
|
|
628
|
-
// )
|
|
629
|
-
// );
|
|
630
|
-
|
|
631
|
-
// propertiesOfProps = [...subTypes, ...baseProps];
|
|
632
|
-
// }
|
|
633
|
-
// }
|
|
634
|
-
|
|
635
|
-
// const result: Props = {};
|
|
636
|
-
|
|
637
|
-
// propertiesOfProps.forEach(prop => {
|
|
638
|
-
// const propName = prop.getName();
|
|
639
|
-
|
|
640
|
-
// // Find type of prop by looking in context of the props object itself.
|
|
641
|
-
// const propType = this.checker.getTypeOfSymbolAtLocation(
|
|
642
|
-
// prop,
|
|
643
|
-
// propsObj.valueDeclaration!
|
|
644
|
-
// );
|
|
645
|
-
|
|
646
|
-
// const jsDocComment = this.findDocComment(prop);
|
|
647
|
-
// const hasCodeBasedDefault = defaultProps[propName] !== undefined;
|
|
648
|
-
|
|
649
|
-
// let defaultValue: { value: any } | null = null;
|
|
650
|
-
|
|
651
|
-
// if (hasCodeBasedDefault) {
|
|
652
|
-
// defaultValue = { value: defaultProps[propName] };
|
|
653
|
-
// } else if (jsDocComment.tags.default) {
|
|
654
|
-
// defaultValue = { value: jsDocComment.tags.default };
|
|
655
|
-
// }
|
|
656
|
-
|
|
657
|
-
// const parent = getParentType(prop);
|
|
658
|
-
// const parents = getDeclarations(prop);
|
|
659
|
-
// const declarations = prop.declarations || [];
|
|
660
|
-
// const baseProp = baseProps.find(p => p.getName() === propName);
|
|
661
|
-
|
|
662
|
-
// const required =
|
|
663
|
-
// !isOptional(prop) &&
|
|
664
|
-
// !hasCodeBasedDefault &&
|
|
665
|
-
// // If in a intersection or union check original declaration for "?"
|
|
666
|
-
// // @ts-ignore
|
|
667
|
-
// declarations.every(d => !d.questionToken) &&
|
|
668
|
-
// (!baseProp || !isOptional(baseProp));
|
|
669
|
-
|
|
670
|
-
// const type = jsDocComment.tags.type
|
|
671
|
-
// ? {
|
|
672
|
-
// name: jsDocComment.tags.type
|
|
673
|
-
// }
|
|
674
|
-
// : this.getDocgenType(propType, required);
|
|
675
|
-
|
|
676
|
-
// result[propName] = {
|
|
677
|
-
// defaultValue,
|
|
678
|
-
// description: jsDocComment.fullComment,
|
|
679
|
-
// name: propName,
|
|
680
|
-
// parent,
|
|
681
|
-
// declarations: parents,
|
|
682
|
-
// required,
|
|
683
|
-
// type
|
|
684
|
-
// };
|
|
685
|
-
// });
|
|
686
|
-
|
|
687
|
-
// return result;
|
|
688
|
-
// }
|
|
689
|
-
|
|
690
|
-
// public findDocComment(symbol: ts.Symbol): JSDoc {
|
|
691
|
-
// const comment = this.getFullJsDocComment(symbol);
|
|
692
|
-
// if (comment.fullComment || comment.tags.default) {
|
|
693
|
-
// return comment;
|
|
694
|
-
// }
|
|
695
|
-
|
|
696
|
-
// const rootSymbols = this.checker.getRootSymbols(symbol);
|
|
697
|
-
// const commentsOnRootSymbols = rootSymbols
|
|
698
|
-
// .filter(x => x !== symbol)
|
|
699
|
-
// .map(x => this.getFullJsDocComment(x))
|
|
700
|
-
// .filter(x => !!x.fullComment || !!comment.tags.default);
|
|
701
|
-
|
|
702
|
-
// if (commentsOnRootSymbols.length) {
|
|
703
|
-
// return commentsOnRootSymbols[0];
|
|
704
|
-
// }
|
|
705
|
-
|
|
706
|
-
// return defaultJSDoc;
|
|
707
|
-
// }
|
|
708
|
-
|
|
709
|
-
// /**
|
|
710
|
-
// * Extracts a full JsDoc comment from a symbol, even
|
|
711
|
-
// * though TypeScript has broken down the JsDoc comment into plain
|
|
712
|
-
// * text and JsDoc tags.
|
|
713
|
-
// */
|
|
714
|
-
// public getFullJsDocComment(symbol: ts.Symbol): JSDoc {
|
|
715
|
-
// // in some cases this can be undefined (Pick<Type, 'prop1'|'prop2'>)
|
|
716
|
-
// if (symbol.getDocumentationComment === undefined) {
|
|
717
|
-
// return defaultJSDoc;
|
|
718
|
-
// }
|
|
719
|
-
|
|
720
|
-
// let mainComment = ts.displayPartsToString(
|
|
721
|
-
// symbol.getDocumentationComment(this.checker)
|
|
722
|
-
// );
|
|
723
|
-
|
|
724
|
-
// if (mainComment) {
|
|
725
|
-
// mainComment = mainComment.replace('\r\n', '\n');
|
|
726
|
-
// }
|
|
727
|
-
|
|
728
|
-
// const tags = symbol.getJsDocTags() || [];
|
|
729
|
-
|
|
730
|
-
// const tagComments: string[] = [];
|
|
731
|
-
// const tagMap: StringIndexedObject<string> = {};
|
|
732
|
-
|
|
733
|
-
// tags.forEach(tag => {
|
|
734
|
-
// const trimmedText = (tag.text || '').trim();
|
|
735
|
-
// const currentValue = tagMap[tag.name];
|
|
736
|
-
// tagMap[tag.name] = currentValue
|
|
737
|
-
// ? currentValue + '\n' + trimmedText
|
|
738
|
-
// : trimmedText;
|
|
739
|
-
|
|
740
|
-
// if (['default', 'type'].indexOf(tag.name) < 0) {
|
|
741
|
-
// tagComments.push(formatTag(tag));
|
|
742
|
-
// }
|
|
743
|
-
// });
|
|
744
|
-
|
|
745
|
-
// return {
|
|
746
|
-
// description: mainComment,
|
|
747
|
-
// fullComment: (mainComment + '\n' + tagComments.join('\n')).trim(),
|
|
748
|
-
// tags: tagMap
|
|
749
|
-
// };
|
|
750
|
-
// }
|
|
751
|
-
|
|
752
|
-
// getFunctionStatement(statement: ts.Statement) {
|
|
753
|
-
// if (ts.isFunctionDeclaration(statement)) {
|
|
754
|
-
// return statement;
|
|
755
|
-
// }
|
|
756
|
-
|
|
757
|
-
// if (ts.isVariableStatement(statement)) {
|
|
758
|
-
// let initializer =
|
|
759
|
-
// statement.declarationList &&
|
|
760
|
-
// statement.declarationList.declarations[0].initializer;
|
|
761
|
-
|
|
762
|
-
// // Look at forwardRef function argument
|
|
763
|
-
// if (initializer && ts.isCallExpression(initializer)) {
|
|
764
|
-
// const symbol = this.checker.getSymbolAtLocation(initializer.expression);
|
|
765
|
-
// if (!symbol || symbol.getName() !== 'forwardRef') return;
|
|
766
|
-
// initializer = initializer.arguments[0];
|
|
767
|
-
// }
|
|
768
|
-
|
|
769
|
-
// if (
|
|
770
|
-
// initializer &&
|
|
771
|
-
// (ts.isArrowFunction(initializer) ||
|
|
772
|
-
// ts.isFunctionExpression(initializer))
|
|
773
|
-
// ) {
|
|
774
|
-
// return initializer;
|
|
775
|
-
// }
|
|
776
|
-
// }
|
|
777
|
-
// }
|
|
778
|
-
|
|
779
|
-
// public extractDefaultPropsFromComponent(
|
|
780
|
-
// symbol: ts.Symbol,
|
|
781
|
-
// source: ts.SourceFile
|
|
782
|
-
// ) {
|
|
783
|
-
// let possibleStatements = [
|
|
784
|
-
// ...source.statements
|
|
785
|
-
// // ensure that name property is available
|
|
786
|
-
// .filter(stmt => !!(stmt as ts.ClassDeclaration).name)
|
|
787
|
-
// .filter(
|
|
788
|
-
// stmt =>
|
|
789
|
-
// this.checker.getSymbolAtLocation(
|
|
790
|
-
// (stmt as ts.ClassDeclaration).name!
|
|
791
|
-
// ) === symbol
|
|
792
|
-
// ),
|
|
793
|
-
// ...source.statements.filter(
|
|
794
|
-
// stmt => ts.isExpressionStatement(stmt) || ts.isVariableStatement(stmt)
|
|
795
|
-
// )
|
|
796
|
-
// ];
|
|
797
|
-
|
|
798
|
-
// return possibleStatements.reduce((res, statement) => {
|
|
799
|
-
// if (statementIsClassDeclaration(statement) && statement.members.length) {
|
|
800
|
-
// const possibleDefaultProps = statement.members.filter(
|
|
801
|
-
// member =>
|
|
802
|
-
// member.name && getPropertyName(member.name) === 'defaultProps'
|
|
803
|
-
// );
|
|
804
|
-
|
|
805
|
-
// if (!possibleDefaultProps.length) {
|
|
806
|
-
// return res;
|
|
807
|
-
// }
|
|
808
|
-
|
|
809
|
-
// const defaultProps = possibleDefaultProps[0];
|
|
810
|
-
// let initializer = (defaultProps as ts.PropertyDeclaration).initializer;
|
|
811
|
-
// if (!initializer) {
|
|
812
|
-
// return res;
|
|
813
|
-
// }
|
|
814
|
-
// let properties = (initializer as ts.ObjectLiteralExpression).properties;
|
|
815
|
-
|
|
816
|
-
// while (ts.isIdentifier(initializer as ts.Identifier)) {
|
|
817
|
-
// const defaultPropsReference = this.checker.getSymbolAtLocation(
|
|
818
|
-
// initializer as ts.Node
|
|
819
|
-
// );
|
|
820
|
-
// if (defaultPropsReference) {
|
|
821
|
-
// const declarations = defaultPropsReference.getDeclarations();
|
|
822
|
-
|
|
823
|
-
// if (declarations) {
|
|
824
|
-
// initializer = (declarations[0] as ts.VariableDeclaration)
|
|
825
|
-
// .initializer;
|
|
826
|
-
// properties = (initializer as ts.ObjectLiteralExpression)
|
|
827
|
-
// .properties;
|
|
828
|
-
// }
|
|
829
|
-
// }
|
|
830
|
-
// }
|
|
831
|
-
|
|
832
|
-
// let propMap = {};
|
|
833
|
-
|
|
834
|
-
// if (properties) {
|
|
835
|
-
// propMap = this.getPropMap(
|
|
836
|
-
// properties as ts.NodeArray<ts.PropertyAssignment>
|
|
837
|
-
// );
|
|
838
|
-
// }
|
|
839
|
-
|
|
840
|
-
// return {
|
|
841
|
-
// ...res,
|
|
842
|
-
// ...propMap
|
|
843
|
-
// };
|
|
844
|
-
// } else if (statementIsStatelessWithDefaultProps(statement)) {
|
|
845
|
-
// let propMap = {};
|
|
846
|
-
// (statement as ts.ExpressionStatement).getChildren().forEach(child => {
|
|
847
|
-
// let { right } = child as ts.BinaryExpression;
|
|
848
|
-
|
|
849
|
-
// if (right && ts.isIdentifier(right)) {
|
|
850
|
-
// const value = ((source as any).locals as ts.SymbolTable).get(
|
|
851
|
-
// right.escapedText
|
|
852
|
-
// );
|
|
853
|
-
|
|
854
|
-
// if (
|
|
855
|
-
// value &&
|
|
856
|
-
// value.valueDeclaration &&
|
|
857
|
-
// ts.isVariableDeclaration(value.valueDeclaration) &&
|
|
858
|
-
// value.valueDeclaration.initializer
|
|
859
|
-
// ) {
|
|
860
|
-
// right = value.valueDeclaration.initializer;
|
|
861
|
-
// }
|
|
862
|
-
// }
|
|
863
|
-
|
|
864
|
-
// if (right) {
|
|
865
|
-
// const { properties } = right as ts.ObjectLiteralExpression;
|
|
866
|
-
// if (properties) {
|
|
867
|
-
// propMap = this.getPropMap(
|
|
868
|
-
// properties as ts.NodeArray<ts.PropertyAssignment>
|
|
869
|
-
// );
|
|
870
|
-
// }
|
|
871
|
-
// }
|
|
872
|
-
// });
|
|
873
|
-
// return {
|
|
874
|
-
// ...res,
|
|
875
|
-
// ...propMap
|
|
876
|
-
// };
|
|
877
|
-
// } else {
|
|
878
|
-
// }
|
|
879
|
-
|
|
880
|
-
// const functionStatement = this.getFunctionStatement(statement);
|
|
881
|
-
|
|
882
|
-
// // Extracting default values from props destructuring
|
|
883
|
-
// if (functionStatement && functionStatement.parameters.length) {
|
|
884
|
-
// const { name } = functionStatement.parameters[0];
|
|
885
|
-
|
|
886
|
-
// if (ts.isObjectBindingPattern(name)) {
|
|
887
|
-
// return {
|
|
888
|
-
// ...res,
|
|
889
|
-
// ...this.getPropMap(name.elements)
|
|
890
|
-
// };
|
|
891
|
-
// }
|
|
892
|
-
// }
|
|
893
|
-
|
|
894
|
-
// return res;
|
|
895
|
-
// }, {});
|
|
896
|
-
// }
|
|
897
|
-
|
|
898
|
-
// public getLiteralValueFromPropertyAssignment(
|
|
899
|
-
// property: ts.PropertyAssignment | ts.BindingElement
|
|
900
|
-
// ): string | boolean | number | null | undefined {
|
|
901
|
-
// let { initializer } = property;
|
|
902
|
-
|
|
903
|
-
// // Shorthand properties, so inflect their actual value
|
|
904
|
-
// if (!initializer) {
|
|
905
|
-
// if (ts.isShorthandPropertyAssignment(property)) {
|
|
906
|
-
// const symbol = this.checker.getShorthandAssignmentValueSymbol(property);
|
|
907
|
-
// const decl =
|
|
908
|
-
// symbol && (symbol.valueDeclaration as ts.VariableDeclaration);
|
|
909
|
-
|
|
910
|
-
// if (decl && decl.initializer) {
|
|
911
|
-
// initializer = decl.initializer!;
|
|
912
|
-
// }
|
|
913
|
-
// }
|
|
914
|
-
// }
|
|
915
|
-
|
|
916
|
-
// if (!initializer) {
|
|
917
|
-
// return undefined;
|
|
918
|
-
// }
|
|
919
|
-
|
|
920
|
-
// // Literal values
|
|
921
|
-
// switch (initializer.kind) {
|
|
922
|
-
// case ts.SyntaxKind.FalseKeyword:
|
|
923
|
-
// return this.savePropValueAsString ? 'false' : false;
|
|
924
|
-
// case ts.SyntaxKind.TrueKeyword:
|
|
925
|
-
// return this.savePropValueAsString ? 'true' : true;
|
|
926
|
-
// case ts.SyntaxKind.StringLiteral:
|
|
927
|
-
// return (initializer as ts.StringLiteral).text.trim();
|
|
928
|
-
// case ts.SyntaxKind.PrefixUnaryExpression:
|
|
929
|
-
// return this.savePropValueAsString
|
|
930
|
-
// ? initializer.getFullText().trim()
|
|
931
|
-
// : Number((initializer as ts.PrefixUnaryExpression).getFullText());
|
|
932
|
-
// case ts.SyntaxKind.NumericLiteral:
|
|
933
|
-
// return this.savePropValueAsString
|
|
934
|
-
// ? `${(initializer as ts.NumericLiteral).text}`
|
|
935
|
-
// : Number((initializer as ts.NumericLiteral).text);
|
|
936
|
-
// case ts.SyntaxKind.NullKeyword:
|
|
937
|
-
// return this.savePropValueAsString ? 'null' : null;
|
|
938
|
-
// case ts.SyntaxKind.Identifier:
|
|
939
|
-
// // can potentially find other identifiers in the source and map those in the future
|
|
940
|
-
// return (initializer as ts.Identifier).text === 'undefined'
|
|
941
|
-
// ? 'undefined'
|
|
942
|
-
// : null;
|
|
943
|
-
// case ts.SyntaxKind.PropertyAccessExpression: {
|
|
944
|
-
// const symbol = this.checker.getSymbolAtLocation(
|
|
945
|
-
// initializer as ts.PropertyAccessExpression
|
|
946
|
-
// );
|
|
947
|
-
|
|
948
|
-
// if (symbol && symbol.declarations && symbol.declarations.length) {
|
|
949
|
-
// const declaration = symbol.declarations[0];
|
|
950
|
-
|
|
951
|
-
// if (
|
|
952
|
-
// ts.isBindingElement(declaration) ||
|
|
953
|
-
// ts.isPropertyAssignment(declaration)
|
|
954
|
-
// ) {
|
|
955
|
-
// return this.getLiteralValueFromPropertyAssignment(declaration);
|
|
956
|
-
// }
|
|
957
|
-
// }
|
|
958
|
-
// }
|
|
959
|
-
// case ts.SyntaxKind.ObjectLiteralExpression:
|
|
960
|
-
// default:
|
|
961
|
-
// try {
|
|
962
|
-
// return initializer.getText();
|
|
963
|
-
// } catch (e) {
|
|
964
|
-
// return null;
|
|
965
|
-
// }
|
|
966
|
-
// }
|
|
967
|
-
// }
|
|
968
|
-
|
|
969
|
-
// public getPropMap(
|
|
970
|
-
// properties: ts.NodeArray<ts.PropertyAssignment | ts.BindingElement>
|
|
971
|
-
// ): StringIndexedObject<string | boolean | number | null> {
|
|
972
|
-
// const propMap = properties.reduce((acc, property) => {
|
|
973
|
-
// if (ts.isSpreadAssignment(property) || !property.name) {
|
|
974
|
-
// return acc;
|
|
975
|
-
// }
|
|
976
|
-
|
|
977
|
-
// const literalValue = this.getLiteralValueFromPropertyAssignment(property);
|
|
978
|
-
// const propertyName = getPropertyName(property.name);
|
|
979
|
-
|
|
980
|
-
// if (
|
|
981
|
-
// (typeof literalValue === 'string' ||
|
|
982
|
-
// typeof literalValue === 'number' ||
|
|
983
|
-
// typeof literalValue === 'boolean' ||
|
|
984
|
-
// literalValue === null) &&
|
|
985
|
-
// propertyName !== null
|
|
986
|
-
// ) {
|
|
987
|
-
// acc[propertyName] = literalValue;
|
|
988
|
-
// }
|
|
989
|
-
|
|
990
|
-
// return acc;
|
|
991
|
-
// }, {} as StringIndexedObject<string | boolean | number | null>);
|
|
992
|
-
|
|
993
|
-
// return propMap;
|
|
994
|
-
// }
|
|
995
|
-
// }
|
|
996
|
-
|
|
997
|
-
// function statementIsClassDeclaration(
|
|
998
|
-
// statement: ts.Statement
|
|
999
|
-
// ): statement is ts.ClassDeclaration {
|
|
1000
|
-
// return !!(statement as ts.ClassDeclaration).members;
|
|
1001
|
-
// }
|
|
1002
|
-
|
|
1003
|
-
// function statementIsStatelessWithDefaultProps(
|
|
1004
|
-
// statement: ts.Statement
|
|
1005
|
-
// ): boolean {
|
|
1006
|
-
// const children = (statement as ts.ExpressionStatement).getChildren();
|
|
1007
|
-
// for (const child of children) {
|
|
1008
|
-
// const { left } = child as ts.BinaryExpression;
|
|
1009
|
-
// if (left) {
|
|
1010
|
-
// const { name } = left as ts.PropertyAccessExpression;
|
|
1011
|
-
// if (name && name.escapedText === 'defaultProps') {
|
|
1012
|
-
// return true;
|
|
1013
|
-
// }
|
|
1014
|
-
// }
|
|
1015
|
-
// }
|
|
1016
|
-
// return false;
|
|
1017
|
-
// }
|
|
1018
|
-
|
|
1019
|
-
// function getPropertyName(
|
|
1020
|
-
// name: ts.PropertyName | ts.BindingPattern
|
|
1021
|
-
// ): string | null {
|
|
1022
|
-
// switch (name.kind) {
|
|
1023
|
-
// case ts.SyntaxKind.NumericLiteral:
|
|
1024
|
-
// case ts.SyntaxKind.StringLiteral:
|
|
1025
|
-
// case ts.SyntaxKind.Identifier:
|
|
1026
|
-
// return name.text;
|
|
1027
|
-
// case ts.SyntaxKind.ComputedPropertyName:
|
|
1028
|
-
// return name.getText();
|
|
1029
|
-
// default:
|
|
1030
|
-
// return null;
|
|
1031
|
-
// }
|
|
1032
|
-
// }
|
|
1033
|
-
|
|
1034
|
-
// function formatTag(tag: ts.JSDocTagInfo) {
|
|
1035
|
-
// let result = '@' + tag.name;
|
|
1036
|
-
// if (tag.text) {
|
|
1037
|
-
// result += ' ' + tag.text;
|
|
1038
|
-
// }
|
|
1039
|
-
// return result;
|
|
1040
|
-
// }
|
|
1041
|
-
|
|
1042
|
-
// function getTextValueOfClassMember(
|
|
1043
|
-
// classDeclaration: ts.ClassDeclaration,
|
|
1044
|
-
// memberName: string
|
|
1045
|
-
// ): string {
|
|
1046
|
-
// const classDeclarationMembers = classDeclaration.members || [];
|
|
1047
|
-
// const [textValue] =
|
|
1048
|
-
// classDeclarationMembers &&
|
|
1049
|
-
// classDeclarationMembers
|
|
1050
|
-
// .filter(member => ts.isPropertyDeclaration(member))
|
|
1051
|
-
// .filter(member => {
|
|
1052
|
-
// const name = ts.getNameOfDeclaration(member) as ts.Identifier;
|
|
1053
|
-
// return name && name.text === memberName;
|
|
1054
|
-
// })
|
|
1055
|
-
// .map(member => {
|
|
1056
|
-
// const property = member as ts.PropertyDeclaration;
|
|
1057
|
-
// return (
|
|
1058
|
-
// property.initializer && (property.initializer as ts.Identifier).text
|
|
1059
|
-
// );
|
|
1060
|
-
// });
|
|
1061
|
-
|
|
1062
|
-
// return textValue || '';
|
|
1063
|
-
// }
|
|
1064
|
-
|
|
1065
|
-
// function getTextValueOfFunctionProperty(
|
|
1066
|
-
// exp: ts.Symbol,
|
|
1067
|
-
// source: ts.SourceFile,
|
|
1068
|
-
// propertyName: string
|
|
1069
|
-
// ) {
|
|
1070
|
-
// const [textValue] = source.statements
|
|
1071
|
-
// .filter(statement => ts.isExpressionStatement(statement))
|
|
1072
|
-
// .filter(statement => {
|
|
1073
|
-
// const expr = (statement as ts.ExpressionStatement)
|
|
1074
|
-
// .expression as ts.BinaryExpression;
|
|
1075
|
-
// return (
|
|
1076
|
-
// expr.left &&
|
|
1077
|
-
// (expr.left as ts.PropertyAccessExpression).name &&
|
|
1078
|
-
// (expr.left as ts.PropertyAccessExpression).name.escapedText ===
|
|
1079
|
-
// propertyName
|
|
1080
|
-
// );
|
|
1081
|
-
// })
|
|
1082
|
-
// .filter(statement => {
|
|
1083
|
-
// const expr = (statement as ts.ExpressionStatement)
|
|
1084
|
-
// .expression as ts.BinaryExpression;
|
|
1085
|
-
|
|
1086
|
-
// return (
|
|
1087
|
-
// ((expr.left as ts.PropertyAccessExpression).expression as ts.Identifier)
|
|
1088
|
-
// .escapedText === exp.getName()
|
|
1089
|
-
// );
|
|
1090
|
-
// })
|
|
1091
|
-
// .filter(statement => {
|
|
1092
|
-
// return ts.isStringLiteral(
|
|
1093
|
-
// ((statement as ts.ExpressionStatement)
|
|
1094
|
-
// .expression as ts.BinaryExpression).right
|
|
1095
|
-
// );
|
|
1096
|
-
// })
|
|
1097
|
-
// .map(statement => {
|
|
1098
|
-
// return (((statement as ts.ExpressionStatement)
|
|
1099
|
-
// .expression as ts.BinaryExpression).right as ts.Identifier).text;
|
|
1100
|
-
// });
|
|
1101
|
-
|
|
1102
|
-
// return textValue || '';
|
|
1103
|
-
// }
|
|
1104
|
-
|
|
1105
|
-
// function computeComponentName(exp: ts.Symbol, source: ts.SourceFile) {
|
|
1106
|
-
// const exportName = exp.getName();
|
|
1107
|
-
|
|
1108
|
-
// const statelessDisplayName = getTextValueOfFunctionProperty(
|
|
1109
|
-
// exp,
|
|
1110
|
-
// source,
|
|
1111
|
-
// 'displayName'
|
|
1112
|
-
// );
|
|
1113
|
-
|
|
1114
|
-
// const statefulDisplayName =
|
|
1115
|
-
// exp.valueDeclaration &&
|
|
1116
|
-
// ts.isClassDeclaration(exp.valueDeclaration) &&
|
|
1117
|
-
// getTextValueOfClassMember(exp.valueDeclaration, 'displayName');
|
|
1118
|
-
|
|
1119
|
-
// if (statelessDisplayName || statefulDisplayName) {
|
|
1120
|
-
// return statelessDisplayName || statefulDisplayName || '';
|
|
1121
|
-
// }
|
|
1122
|
-
|
|
1123
|
-
// if (
|
|
1124
|
-
// exportName === 'default' ||
|
|
1125
|
-
// exportName === '__function' ||
|
|
1126
|
-
// exportName === 'Stateless' ||
|
|
1127
|
-
// exportName === 'StyledComponentClass' ||
|
|
1128
|
-
// exportName === 'StyledComponent' ||
|
|
1129
|
-
// exportName === 'FunctionComponent' ||
|
|
1130
|
-
// exportName === 'StatelessComponent' ||
|
|
1131
|
-
// exportName === 'ForwardRefExoticComponent'
|
|
1132
|
-
// ) {
|
|
1133
|
-
// return getDefaultExportForFile(source);
|
|
1134
|
-
// } else {
|
|
1135
|
-
// return exportName;
|
|
1136
|
-
// }
|
|
1137
|
-
// }
|
|
1138
|
-
|
|
1139
|
-
// // Default export for a file: named after file
|
|
1140
|
-
// export function getDefaultExportForFile(source: ts.SourceFile) {
|
|
1141
|
-
// const name = path.basename(source.fileName, path.extname(source.fileName));
|
|
1142
|
-
// const filename =
|
|
1143
|
-
// name === 'index' ? path.basename(path.dirname(source.fileName)) : name;
|
|
1144
|
-
|
|
1145
|
-
// // JS identifiers must starts with a letter, and contain letters and/or numbers
|
|
1146
|
-
// // So, you could not take filename as is
|
|
1147
|
-
// const identifier = filename
|
|
1148
|
-
// .replace(/^[^A-Z]*/gi, '')
|
|
1149
|
-
// .replace(/[^A-Z0-9]*/gi, '');
|
|
1150
|
-
|
|
1151
|
-
// return identifier.length ? identifier : 'DefaultName';
|
|
1152
|
-
// }
|
|
1153
|
-
|
|
1154
|
-
// function isTypeLiteral(node: ts.Node): node is ts.TypeLiteralNode {
|
|
1155
|
-
// return node.kind === ts.SyntaxKind.TypeLiteral;
|
|
1156
|
-
// }
|
|
1157
|
-
|
|
1158
|
-
// function getDeclarations(prop: ts.Symbol): ParentType[] | undefined {
|
|
1159
|
-
// const declarations = prop.getDeclarations();
|
|
1160
|
-
|
|
1161
|
-
// if (declarations === undefined || declarations.length === 0) {
|
|
1162
|
-
// return undefined;
|
|
1163
|
-
// }
|
|
1164
|
-
|
|
1165
|
-
// const parents: ParentType[] = [];
|
|
1166
|
-
|
|
1167
|
-
// for (let declaration of declarations) {
|
|
1168
|
-
// const { parent } = declaration;
|
|
1169
|
-
|
|
1170
|
-
// if (!isTypeLiteral(parent) && !isInterfaceOrTypeAliasDeclaration(parent)) {
|
|
1171
|
-
// continue;
|
|
1172
|
-
// }
|
|
1173
|
-
|
|
1174
|
-
// const parentName =
|
|
1175
|
-
// 'name' in parent
|
|
1176
|
-
// ? (parent as InterfaceOrTypeAliasDeclaration).name.text
|
|
1177
|
-
// : 'TypeLiteral';
|
|
1178
|
-
|
|
1179
|
-
// const { fileName } = (parent as
|
|
1180
|
-
// | InterfaceOrTypeAliasDeclaration
|
|
1181
|
-
// | ts.TypeLiteralNode).getSourceFile();
|
|
1182
|
-
|
|
1183
|
-
// parents.push({
|
|
1184
|
-
// fileName: trimFileName(fileName),
|
|
1185
|
-
// name: parentName
|
|
1186
|
-
// });
|
|
1187
|
-
// }
|
|
1188
|
-
|
|
1189
|
-
// return parents;
|
|
1190
|
-
// }
|
|
1191
|
-
|
|
1192
|
-
// function trimFileName(fileName: string) {
|
|
1193
|
-
// const fileNameParts = fileName.split('/');
|
|
1194
|
-
// const trimmedFileNameParts = fileNameParts.slice();
|
|
1195
|
-
|
|
1196
|
-
// while (trimmedFileNameParts.length) {
|
|
1197
|
-
// if (trimmedFileNameParts[0] === currentDirectoryName) {
|
|
1198
|
-
// break;
|
|
1199
|
-
// }
|
|
1200
|
-
// trimmedFileNameParts.splice(0, 1);
|
|
1201
|
-
// }
|
|
1202
|
-
// let trimmedFileName;
|
|
1203
|
-
// if (trimmedFileNameParts.length) {
|
|
1204
|
-
// trimmedFileName = trimmedFileNameParts.join('/');
|
|
1205
|
-
// } else {
|
|
1206
|
-
// trimmedFileName = fileName;
|
|
1207
|
-
// }
|
|
1208
|
-
|
|
1209
|
-
// return trimmedFileName;
|
|
1210
|
-
// }
|
|
1211
|
-
|
|
1212
|
-
// function getParentType(prop: ts.Symbol): ParentType | undefined {
|
|
1213
|
-
// const declarations = prop.getDeclarations();
|
|
1214
|
-
|
|
1215
|
-
// if (declarations == null || declarations.length === 0) {
|
|
1216
|
-
// return undefined;
|
|
1217
|
-
// }
|
|
1218
|
-
|
|
1219
|
-
// // Props can be declared only in one place
|
|
1220
|
-
// const { parent } = declarations[0];
|
|
1221
|
-
|
|
1222
|
-
// if (!isInterfaceOrTypeAliasDeclaration(parent)) {
|
|
1223
|
-
// return undefined;
|
|
1224
|
-
// }
|
|
1225
|
-
|
|
1226
|
-
// const parentName = parent.name.text;
|
|
1227
|
-
// const { fileName } = parent.getSourceFile();
|
|
1228
|
-
|
|
1229
|
-
// return {
|
|
1230
|
-
// fileName: trimFileName(fileName),
|
|
1231
|
-
// name: parentName
|
|
1232
|
-
// };
|
|
1233
|
-
// }
|
|
1234
|
-
|
|
1235
|
-
// function isInterfaceOrTypeAliasDeclaration(
|
|
1236
|
-
// node: ts.Node
|
|
1237
|
-
// ): node is ts.InterfaceDeclaration | ts.TypeAliasDeclaration {
|
|
1238
|
-
// return (
|
|
1239
|
-
// node.kind === ts.SyntaxKind.InterfaceDeclaration ||
|
|
1240
|
-
// node.kind === ts.SyntaxKind.TypeAliasDeclaration
|
|
1241
|
-
// );
|
|
1242
|
-
// }
|
|
1243
|
-
|
|
1244
|
-
// function parseWithProgramProvider(
|
|
1245
|
-
// filePathOrPaths: string | string[],
|
|
1246
|
-
// compilerOptions: ts.CompilerOptions,
|
|
1247
|
-
// parserOpts: ParserOptions,
|
|
1248
|
-
// programProvider?: () => ts.Program
|
|
1249
|
-
// ): ComponentDoc[] {
|
|
1250
|
-
// const filePaths = Array.isArray(filePathOrPaths)
|
|
1251
|
-
// ? filePathOrPaths
|
|
1252
|
-
// : [filePathOrPaths];
|
|
1253
|
-
|
|
1254
|
-
// const program = programProvider
|
|
1255
|
-
// ? programProvider()
|
|
1256
|
-
// : ts.createProgram(filePaths, compilerOptions);
|
|
1257
|
-
|
|
1258
|
-
// const parser = new Parser(program, parserOpts);
|
|
1259
|
-
|
|
1260
|
-
// const checker = program.getTypeChecker();
|
|
1261
|
-
|
|
1262
|
-
// return filePaths
|
|
1263
|
-
// .map(filePath => program.getSourceFile(filePath))
|
|
1264
|
-
// .filter(
|
|
1265
|
-
// (sourceFile): sourceFile is ts.SourceFile =>
|
|
1266
|
-
// typeof sourceFile !== 'undefined'
|
|
1267
|
-
// )
|
|
1268
|
-
// .reduce<ComponentDoc[]>((docs, sourceFile) => {
|
|
1269
|
-
// const moduleSymbol = checker.getSymbolAtLocation(sourceFile);
|
|
1270
|
-
|
|
1271
|
-
// if (!moduleSymbol) {
|
|
1272
|
-
// return docs;
|
|
1273
|
-
// }
|
|
1274
|
-
|
|
1275
|
-
// const components = checker.getExportsOfModule(moduleSymbol);
|
|
1276
|
-
// const componentDocs: ComponentDoc[] = [];
|
|
1277
|
-
|
|
1278
|
-
// // First document all components
|
|
1279
|
-
// components.forEach(exp => {
|
|
1280
|
-
// const doc = parser.getComponentInfo(
|
|
1281
|
-
// exp,
|
|
1282
|
-
// sourceFile,
|
|
1283
|
-
// parserOpts.componentNameResolver
|
|
1284
|
-
// );
|
|
1285
|
-
|
|
1286
|
-
// if (doc) {
|
|
1287
|
-
// componentDocs.push(doc);
|
|
1288
|
-
// }
|
|
1289
|
-
|
|
1290
|
-
// if (!exp.exports) {
|
|
1291
|
-
// return;
|
|
1292
|
-
// }
|
|
1293
|
-
|
|
1294
|
-
// // Then document any static sub-components
|
|
1295
|
-
// exp.exports.forEach(symbol => {
|
|
1296
|
-
// if (symbol.flags & ts.SymbolFlags.Prototype) {
|
|
1297
|
-
// return;
|
|
1298
|
-
// }
|
|
1299
|
-
|
|
1300
|
-
// if (symbol.flags & ts.SymbolFlags.Method) {
|
|
1301
|
-
// const signature = parser.getCallSignature(symbol);
|
|
1302
|
-
// const returnType = checker.typeToString(signature.getReturnType());
|
|
1303
|
-
|
|
1304
|
-
// if (returnType !== 'Element') {
|
|
1305
|
-
// return;
|
|
1306
|
-
// }
|
|
1307
|
-
// }
|
|
1308
|
-
|
|
1309
|
-
// const doc = parser.getComponentInfo(
|
|
1310
|
-
// symbol,
|
|
1311
|
-
// sourceFile,
|
|
1312
|
-
// parserOpts.componentNameResolver
|
|
1313
|
-
// );
|
|
1314
|
-
|
|
1315
|
-
// if (doc) {
|
|
1316
|
-
// componentDocs.push({
|
|
1317
|
-
// ...doc,
|
|
1318
|
-
// displayName: `${exp.escapedName}.${symbol.escapedName}`
|
|
1319
|
-
// });
|
|
1320
|
-
// }
|
|
1321
|
-
// });
|
|
1322
|
-
// });
|
|
1323
|
-
|
|
1324
|
-
// // Remove any duplicates (for HOC where the names are the same)
|
|
1325
|
-
// const componentDocsNoDuplicates = componentDocs.reduce(
|
|
1326
|
-
// (prevVal, comp) => {
|
|
1327
|
-
// const duplicate = prevVal.find(compDoc => {
|
|
1328
|
-
// return compDoc!.displayName === comp!.displayName;
|
|
1329
|
-
// });
|
|
1330
|
-
// if (duplicate) return prevVal;
|
|
1331
|
-
// return [...prevVal, comp];
|
|
1332
|
-
// },
|
|
1333
|
-
// [] as ComponentDoc[]
|
|
1334
|
-
// );
|
|
1335
|
-
|
|
1336
|
-
// const filteredComponentDocs = componentDocsNoDuplicates.filter(
|
|
1337
|
-
// (comp, index, comps) =>
|
|
1338
|
-
// comps
|
|
1339
|
-
// .slice(index + 1)
|
|
1340
|
-
// .every(innerComp => innerComp!.displayName !== comp!.displayName)
|
|
1341
|
-
// );
|
|
1342
|
-
|
|
1343
|
-
// return [...docs, ...filteredComponentDocs];
|
|
1344
|
-
// }, []);
|
|
1345
|
-
// }
|