32 lines
746 B
TypeScript
32 lines
746 B
TypeScript
import ts from "typescript";
|
|
import { TypeRegistry } from "../registry.ts";
|
|
import { TypeReference } from "./reference.ts";
|
|
|
|
export class FunctionNode {
|
|
private constructor(
|
|
public readonly name: string,
|
|
public readonly parameters: ParameterNode[],
|
|
public readonly returnType?: TypeReference
|
|
) {}
|
|
|
|
public static create(
|
|
registry: TypeRegistry,
|
|
node: ts.FunctionDeclaration,
|
|
symbol?: ts.Symbol
|
|
) {
|
|
return new FunctionNode(
|
|
symbol?.escapedName ?? node?.name?.escapedText ?? "",
|
|
[],
|
|
registry.getOrCreate(node.type)
|
|
);
|
|
}
|
|
}
|
|
|
|
export class ParameterNode {
|
|
constructor(
|
|
public readonly name: string,
|
|
public readonly type: TypeReference,
|
|
public readonly optional: boolean
|
|
) {}
|
|
}
|