UNPKG

@ts-ast-parser/core

Version:

Reflects a simplified version of the TypeScript AST for generating documentation

58 lines 1.65 kB
import { tryAddProperty } from '../utils/try-add-property.js'; import { isBareModuleSpecifier } from '../utils/import.js'; import { ImportKind } from '../models/import.js'; import { RootNodeType } from '../models/node.js'; /** * Represents the reflected node of a side effect import declaration. * For example: `import './foo.js'` */ export class SideEffectImportNode { constructor(node, context) { Object.defineProperty(this, "_node", { 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._context = context; } getTSNode() { return this._node; } getNodeType() { return RootNodeType.Import; } getKind() { return ImportKind.SideEffect; } getContext() { return this._context; } getImportPath() { return this._node.moduleSpecifier.text ?? ''; } isBareModuleSpecifier() { return isBareModuleSpecifier(this.getImportPath()); } /** * Serializes the reflected node * * @returns The reflected node as a serializable object */ serialize() { const tmpl = { kind: ImportKind.SideEffect, importPath: this.getImportPath(), }; tryAddProperty(tmpl, 'bareModuleSpecifier', this.isBareModuleSpecifier()); return tmpl; } } //# sourceMappingURL=side-effect-import-node.js.map