UNPKG

@ts-for-gir/lib

Version:

Typescript .d.ts generator from GIR for gjs

43 lines 1.56 kB
import { IntrospectedNamespaceMember } from "./base.js"; import { isIntrospectable } from "./namespace.js"; import { sanitizeIdentifierName, getAliasType, parseDoc, parseMetadata } from "./util.js"; export class IntrospectedAlias extends IntrospectedNamespaceMember { type; generics; constructor({ namespace, name, type, generics = [], ...args }) { super(name, namespace, { ...args }); this.type = type; this.generics = generics; } accept(visitor) { const node = this.copy({ type: visitor.visitType?.(this.type) }); return visitor.visitAlias?.(node) ?? node; } copy(options) { const { name, namespace, type } = this; return new IntrospectedAlias({ name, namespace, type: options?.type ?? type })._copyBaseProperties(this); } asString(generator) { return generator.generateAlias(this); } static fromXML(element, ns, options) { if (!element.$.name) { console.error(`Alias in ${ns.namespace} lacks name.`); return null; } const alias = new IntrospectedAlias({ namespace: ns, name: sanitizeIdentifierName(ns.namespace, element.$.name), type: getAliasType(ns.namespace, ns, element), isIntrospectable: isIntrospectable(element) }); if (options.loadDocs) { alias.doc = parseDoc(element); alias.metadata = parseMetadata(element); } return alias; } } //# sourceMappingURL=alias.js.map