1 | import * as tsm from 'ts-morph';
|
2 | import {
|
3 | DeclarationKinds,
|
4 | TypeAliasDeclaration,
|
5 | } from '../types/module-declarations';
|
6 | import { formatText } from './format';
|
7 | import { getJSDocs } from './get-jsdocs';
|
8 | import { SourceProvider } from './source-provider';
|
9 |
|
10 | export function isTypeAlias(
|
11 | declaration: tsm.Node
|
12 | ): declaration is tsm.TypeAliasDeclaration {
|
13 | return tsm.Node.isTypeAliasDeclaration(declaration);
|
14 | }
|
15 |
|
16 | export function newTypeAlias({
|
17 | id,
|
18 | name,
|
19 | declaration,
|
20 | getSource,
|
21 | }: {
|
22 | id: string;
|
23 | name: string;
|
24 | declaration: tsm.TypeAliasDeclaration;
|
25 | getSource: SourceProvider;
|
26 | }): TypeAliasDeclaration {
|
27 | const kind = DeclarationKinds.TypeAliasDeclaration;
|
28 | const docs = getJSDocs({ declaration });
|
29 | const source = getSource({ declaration });
|
30 | const signature = getTypeAliasSignature({ declaration });
|
31 |
|
32 | return {
|
33 | kind,
|
34 | id,
|
35 | name,
|
36 | docs,
|
37 | source,
|
38 | signature,
|
39 | };
|
40 | }
|
41 |
|
42 | function getTypeAliasSignature({
|
43 | declaration,
|
44 | }: {
|
45 | declaration: tsm.TypeAliasDeclaration;
|
46 | }): string {
|
47 | const signature = declaration.getText();
|
48 | return formatText(signature);
|
49 | }
|