forked from TypeStrong/typedoc
/
type-parameter.ts
37 lines (30 loc) · 1.43 KB
/
type-parameter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import * as ts from 'typescript';
import { TypeParameterContainer, TypeParameterReflection, TypeParameterType, ReflectionFlag } from '../../models/index';
import { Context } from '../context';
import { Converter } from '../converter';
/**
* Create a type parameter reflection for the given node.
*
* @param context The context object describing the current state the converter is in.
* @param node The type parameter node that should be reflected.
* @returns The newly created type parameter reflection.
*/
export function createTypeParameter(context: Context, node: ts.TypeParameterDeclaration): TypeParameterType | undefined {
if (!node.symbol) {
return;
}
const typeParameter = new TypeParameterType(node.symbol.name);
if (node.constraint) {
typeParameter.constraint = context.converter.convertType(context, node.constraint);
}
const reflection = <TypeParameterContainer> context.scope;
const typeParameterReflection = new TypeParameterReflection(typeParameter, reflection);
typeParameterReflection.flags.setFlag(ReflectionFlag.Exported, reflection.flags.isExported);
if (!reflection.typeParameters) {
reflection.typeParameters = [];
}
reflection.typeParameters.push(typeParameterReflection);
context.registerReflection(typeParameterReflection, node);
context.trigger(Converter.EVENT_CREATE_TYPE_PARAMETER, typeParameterReflection, node);
return typeParameter;
}