@ts-ast-parser/core
Version:
Reflects a simplified version of the TypeScript AST for generating documentation
82 lines • 2.53 kB
JavaScript
import { hasDefaultKeyword } from '../utils/export.js';
import { ExportKind } from '../models/export.js';
import { RootNodeType } from '../models/node.js';
/**
* Represents the reflected node of an export declaration.
* For example: `export const x = 4` or `export class Foo {}`
*/
export class ExportDeclarationNode {
constructor(node, context, declaration) {
Object.defineProperty(this, "_node", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "_declaration", {
enumerable: true,
configurable: true,
writable: true,
value: null
});
Object.defineProperty(this, "_context", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this._node = node;
this._declaration = declaration ?? null;
this._context = context;
}
getName() {
if (this._declaration) {
return this._declaration.name.getText() ?? '';
}
return this._node.name?.getText() ?? '';
}
/**
* The qualified name of the symbol is considered the name of the symbol including the
* parent namespaces where the symbol is defined.
*
* For example: `<NamespaceName1>.<Namespace2>.<SymbolName>`
*
* @returns The name of the symbol prefixed by any parent namespace is inside
*/
getFullyQualifiedName() {
const node = this._declaration ?? this._node;
const symbol = this._context.getSymbol(node);
if (symbol) {
const fullyQualifiedName = this._context.getTypeChecker().getFullyQualifiedName(symbol);
return fullyQualifiedName.split('.').slice(1).join('.');
}
return this.getName();
}
getOriginalName() {
return this.getName();
}
getNodeType() {
return RootNodeType.Export;
}
getContext() {
return this._context;
}
getKind() {
return hasDefaultKeyword(this._node) ? ExportKind.Default : ExportKind.Named;
}
getTSNode() {
return this._node;
}
/**
* Serializes the reflected node
*
* @returns The reflected node as a serializable object
*/
serialize() {
return {
name: this.getFullyQualifiedName(),
kind: this.getKind(),
};
}
}
//# sourceMappingURL=export-declaration-node.js.map