UNPKG

haystack-codegen

Version:

Project Haystack Core code generation tools

120 lines (119 loc) 3.19 kB
import { HNamespace } from 'haystack-core'; /** * Typeguard options. */ export declare enum TypeGuardOptions { entity = "entity", all = "all" } /** * Generate code for a TypeScript document. */ export declare class CodeGenerator { #private; /** * Construct a new code generator. * * @param names The names of the defs to generate the code for. * @param namespace The defs namespace. */ constructor({ names, namespace, typeGuardOptions, }: { names: string[]; namespace: HNamespace; typeGuardOptions: TypeGuardOptions; }); /** * Generate code from a node. * * @returns The TypeScript code. */ generate(): string; /** * Sort alphabetically by names and then features. * * @returns The def names. */ private sortNamesAndFeatures; /** * Add an interface node. * * @param doc The document node. * @param name The name of the interface to add. */ private addInterface; /** * Add the lib for the def to the libs node. * * @param def The def. * @param doc The document node. */ private addLib; /** * Return true if the def is from the core project haystack library. * * @param def The def to test. * @returns True if the def is from the core project haystack library. */ private static isDefFromCorePh; /** * Add the what types the interface extends from by querying the namespace. * * @param name The name of the def to query the super types from. * @param doc The document node. * @param intNode The interface name to add the extend types to. */ private addExtends; /** * Add all the values to the interface node. * * @param name The name of the interface node. * @param tags The tags to query. * @param intNode The interface node to add the values to. */ private addValues; private addValueNode; /** * Return the generic type for the given tag. * * @param tag The tag to resolve the generic parameter from. * @return The generic parameter or an empty string if one can't be resolved. */ private resolveGenericInfo; /** * Resolve the type name using the existing symbol name and kind. * * @param name The name. * @param kind The kind. * @returns The type name to use. */ private resolveType; /** * Add a namespace. * * @param name The name of the def. * @param doc The document node. * @param intNode The interface node. */ private addNamespace; /** * Add a type guard. * * @param name The name of the def. * @param doc The document node. */ private addTypeGuard; /** * Return true if the property already exists on HDict. * * @param prop The property name. * @returns True if it exists. */ private propertyAlreadyExistOnHDict; /** * Remove any duplicates from the array. * * @param names The names process. * @returns The array with no duplicates. */ private removeDuplicates; }