UNPKG

@ts-ast-parser/core

Version:

Reflects a simplified version of the TypeScript AST for generating documentation

78 lines 2.22 kB
import { tryAddProperty } from '../utils/try-add-property.js'; import { ExportKind } from '../models/export.js'; import { RootNodeType } from '../models/node.js'; /** * Represents the reflected node of a named export declaration. * For example: `export { x, y as z }` */ export class NamedExportNode { constructor(node, element, context) { Object.defineProperty(this, "_node", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "_element", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "_context", { enumerable: true, configurable: true, writable: true, value: void 0 }); this._node = node; this._element = element; this._context = context; } getName() { return this._element.name.escapedText ?? ''; } getOriginalName() { return this._element.propertyName?.escapedText ?? this.getName(); } getKind() { return ExportKind.Named; } getNodeType() { return RootNodeType.Export; } getContext() { return this._context; } isTypeOnly() { return !!this._node.isTypeOnly; } getModule() { return this._node.moduleSpecifier?.getText() ?? ''; } getTSNode() { return this._node; } isReexport() { return this.getOriginalName() !== this.getName(); } /** * Serializes the reflected node * * @returns The reflected node as a serializable object */ serialize() { const originalName = this.getOriginalName(); const tmpl = { name: this.getName(), kind: this.getKind(), }; if (originalName !== tmpl.name) { tryAddProperty(tmpl, 'originalName', this.getOriginalName()); } tryAddProperty(tmpl, 'typeOnly', this.isTypeOnly()); tryAddProperty(tmpl, 'module', this.getModule()); return tmpl; } } //# sourceMappingURL=named-export-node.js.map