Skip to content

Commit

Permalink
fix: ConstructorType node support
Browse files Browse the repository at this point in the history
Doesn't render nicely... but it never rendered nicely.
  • Loading branch information
Gerrit0 committed Dec 27, 2020
1 parent 0359a70 commit 7ba17f6
Show file tree
Hide file tree
Showing 5 changed files with 294 additions and 145 deletions.
66 changes: 66 additions & 0 deletions src/lib/converter/types.ts
Expand Up @@ -55,6 +55,7 @@ export function loadConverters() {
for (const actor of [
arrayConverter,
conditionalConverter,
constructorConverter,
exprWithTypeArgsConverter,
functionTypeConverter,
indexedAccessConverter,
Expand Down Expand Up @@ -187,6 +188,71 @@ const conditionalConverter: TypeConverter<
},
};

const constructorConverter: TypeConverter<ts.ConstructorTypeNode, ts.Type> = {
kind: [ts.SyntaxKind.ConstructorType],
convert(context, node) {
const symbol = context.getSymbolAtLocation(node) ?? node.symbol;
const type = context.getTypeAtLocation(node);
if (!symbol || !type) {
return new IntrinsicType("Function");
}

const reflection = new DeclarationReflection(
"__type",
ReflectionKind.Constructor,
context.scope
);
context.registerReflection(reflection, symbol);
context.trigger(ConverterEvents.CREATE_DECLARATION, reflection, node);

const signature = new SignatureReflection(
"__type",
ReflectionKind.ConstructorSignature,
reflection
);
context.registerReflection(signature, void 0);
const signatureCtx = context.withScope(signature);

reflection.signatures = [signature];
signature.type = convertType(signatureCtx, node.type);
signature.parameters = convertParameterNodes(
signatureCtx,
signature,
node.parameters
);
signature.typeParameters = convertTypeParameterNodes(
signatureCtx,
reflection,
node.typeParameters
);

return new ReflectionType(reflection);
},
convertType(context, type) {
if (!type.symbol) {
return new IntrinsicType("Function");
}

const reflection = new DeclarationReflection(
"__type",
ReflectionKind.Constructor,
context.scope
);
context.registerReflection(reflection, type.symbol);
context.trigger(ConverterEvents.CREATE_DECLARATION, reflection);

reflection.signatures = [
createSignature(
context.withScope(reflection),
ReflectionKind.ConstructorSignature,
type.getConstructSignatures()[0]
),
];

return new ReflectionType(reflection);
},
};

const exprWithTypeArgsConverter: TypeConverter<
ts.ExpressionWithTypeArguments,
ts.Type
Expand Down

0 comments on commit 7ba17f6

Please sign in to comment.