@ts-ast-parser/core
Version:
Reflects a simplified version of the TypeScript AST for generating documentation
103 lines • 2.66 kB
JavaScript
import { tryAddProperty } from '../utils/try-add-property.js';
import { CommentNode } from './comment-node.js';
/**
* Represents the reflected node of an enum member
*/
export class EnumMemberNode {
constructor(node, value, context) {
Object.defineProperty(this, "_node", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_value", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_context", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_jsDoc", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this._node = node;
this._value = value;
this._context = context;
this._jsDoc = new CommentNode(node);
}
/**
* The name of the enum member
*
* @returns The name of the enum member
*/
getName() {
return this._node.name.getText() ?? '';
}
/**
* The value of the enum member
*
* @returns The value of the enum member
*/
getValue() {
return this._value;
}
/**
* The context includes useful APIs that are shared across
* all the reflected symbols.
*
* Some APIs include the parsed configuration options, the
* system interface, the type checker
*
* @returns The analyser context
*/
getContext() {
return this._context;
}
/**
* The line position where the enum member is defined
*
* @returns The start line position number
*/
getLine() {
return this._context.getLinePosition(this._node);
}
/**
* The original TypeScript node
*
* @returns The TypeScript AST node related to this reflected node
*/
getTSNode() {
return this._node;
}
/**
* The reflected documentation comment
*
* @returns The JSDoc node
*/
getJSDoc() {
return this._jsDoc;
}
/**
* Serializes the reflected node
*
* @returns The reflected node as a serializable object
*/
serialize() {
const tmpl = {
name: this.getName(),
value: this.getValue(),
};
tryAddProperty(tmpl, 'jsDoc', this.getJSDoc().serialize());
return tmpl;
}
}
//# sourceMappingURL=enum-member-node.js.map