UNPKG

haystack-codegen

Version:

Project Haystack Core code generation tools

56 lines (55 loc) 1.66 kB
"use strict"; /* * Copyright (c) 2021, J2 Innovations. All Rights Reserved */ Object.defineProperty(exports, "__esModule", { value: true }); exports.InterfaceValueNode = void 0; const util_1 = require("./util"); /** * Generates a value line in a TypeScript interface. */ class InterfaceValueNode { name; doc; type; kind; genericType; genericKind; optional; /** * The number of new lines after this node is set dynamically depending on its * position in the parent interface. */ newLines = 1; constructor({ name, type, kind, doc, genericType, genericKind, optional, }) { this.name = name; this.type = type; this.kind = kind; this.doc = doc ?? ''; this.genericType = genericType; this.genericKind = genericKind; this.optional = !!optional; } generateCode(out) { if (this.doc.trim()) { out(' /**'); (0, util_1.writeDocComment)((code) => out(` ${code}`), this.doc); out(' */'); } out(` ${this.name}${this.optional ? '?' : ''}: ${this.type}${this.genericType ? `<${this.genericType}>` : ''}`); } /** * Returns the types (haystack-core constructor names) used with this node. * * @param kind The kind. * @returns The TypeScript haystack constructor names. */ get types() { const types = [(0, util_1.convertKindToCtorName)(this.kind)]; if (this.genericKind) { types.push((0, util_1.convertKindToCtorName)(this.genericKind)); } return types; } } exports.InterfaceValueNode = InterfaceValueNode;