denobox/denogen/parsing/registry.ts
2023-03-08 12:26:10 +01:00

38 lines
850 B
TypeScript

import ts from "typescript";
import { TypeReference } from "./nodes/reference.ts";
/**
* Retrieve and manage types referenced when parsing.
*/
export class TypeRegistry {
private readonly _types: Record<string, TypeReference> = {};
public getOrCreate(node?: ts.TypeNode): TypeReference | undefined {
if (!node) {
return undefined;
}
switch (node.kind) {
case ts.SyntaxKind.TypeReference:
{
const a = node as ts.TypeReferenceNode;
console.log(a.typeName.getText());
}
break;
case ts.SyntaxKind.ArrayType:
{
const b = node as ts.ArrayTypeNode;
console.log("array", b.elementType?.getText());
}
break;
case ts.SyntaxKind.StringKeyword:
console.log("string!");
break;
}
return undefined;
}
}