UNPKG

6.54 kBJavaScriptView Raw
1var __extends = (this && this.__extends) || (function () {
2 var extendStatics = function (d, b) {
3 extendStatics = Object.setPrototypeOf ||
4 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6 return extendStatics(d, b);
7 };
8 return function (d, b) {
9 extendStatics(d, b);
10 function __() { this.constructor = d; }
11 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12 };
13})();
14var __spreadArrays = (this && this.__spreadArrays) || function () {
15 for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
16 for (var r = Array(s), k = 0, i = 0; i < il; i++)
17 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
18 r[k] = a[j];
19 return r;
20};
21import { DocNode, DocNodeKind } from './DocNode';
22import { DocExcerpt, ExcerptKind } from './DocExcerpt';
23import { StringBuilder } from '../emitters/StringBuilder';
24/**
25 * Represents a declaration reference.
26 *
27 * @remarks
28 * Declaration references are TSDoc expressions used by tags such as `{@link}`
29 * or `{@inheritDoc}` that need to refer to another declaration.
30 */
31var DocDeclarationReference = /** @class */ (function (_super) {
32 __extends(DocDeclarationReference, _super);
33 /**
34 * Don't call this directly. Instead use {@link TSDocParser}
35 * @internal
36 */
37 function DocDeclarationReference(parameters) {
38 var _a;
39 var _this = _super.call(this, parameters) || this;
40 if (DocNode.isParsedParameters(parameters)) {
41 if (parameters.packageNameExcerpt) {
42 _this._packageNameExcerpt = new DocExcerpt({
43 configuration: _this.configuration,
44 excerptKind: ExcerptKind.DeclarationReference_PackageName,
45 content: parameters.packageNameExcerpt
46 });
47 }
48 if (parameters.importPathExcerpt) {
49 _this._importPathExcerpt = new DocExcerpt({
50 configuration: _this.configuration,
51 excerptKind: ExcerptKind.DeclarationReference_ImportPath,
52 content: parameters.importPathExcerpt
53 });
54 }
55 if (parameters.importHashExcerpt) {
56 _this._importHashExcerpt = new DocExcerpt({
57 configuration: _this.configuration,
58 excerptKind: ExcerptKind.DeclarationReference_ImportHash,
59 content: parameters.importHashExcerpt
60 });
61 }
62 if (parameters.spacingAfterImportHashExcerpt) {
63 _this._spacingAfterImportHashExcerpt = new DocExcerpt({
64 configuration: _this.configuration,
65 excerptKind: ExcerptKind.Spacing,
66 content: parameters.spacingAfterImportHashExcerpt
67 });
68 }
69 }
70 else {
71 _this._packageName = parameters.packageName;
72 _this._importPath = parameters.importPath;
73 }
74 _this._memberReferences = [];
75 if (parameters.memberReferences) {
76 (_a = _this._memberReferences).push.apply(_a, parameters.memberReferences);
77 }
78 return _this;
79 }
80 Object.defineProperty(DocDeclarationReference.prototype, "kind", {
81 /** @override */
82 get: function () {
83 return DocNodeKind.DeclarationReference;
84 },
85 enumerable: false,
86 configurable: true
87 });
88 Object.defineProperty(DocDeclarationReference.prototype, "packageName", {
89 /**
90 * The optional package name, which may optionally include an NPM scope.
91 *
92 * Example: `"@scope/my-package"`
93 */
94 get: function () {
95 if (this._packageName === undefined) {
96 if (this._packageNameExcerpt !== undefined) {
97 this._packageName = this._packageNameExcerpt.content.toString();
98 }
99 }
100 return this._packageName;
101 },
102 enumerable: false,
103 configurable: true
104 });
105 Object.defineProperty(DocDeclarationReference.prototype, "importPath", {
106 /**
107 * The optional import path. If a package name is provided, then if an import path is provided,
108 * the path must start with a "/" delimiter; otherwise paths are resolved relative to the source file
109 * containing the reference.
110 *
111 * Example: `"/path1/path2"`
112 * Example: `"./path1/path2"`
113 * Example: `"../path2/path2"`
114 */
115 get: function () {
116 if (this._importPath === undefined) {
117 if (this._importPathExcerpt !== undefined) {
118 this._importPath = this._importPathExcerpt.content.toString();
119 }
120 }
121 return this._importPath;
122 },
123 enumerable: false,
124 configurable: true
125 });
126 Object.defineProperty(DocDeclarationReference.prototype, "memberReferences", {
127 /**
128 * The chain of member references that indicate the declaration being referenced.
129 * If this list is empty, then either the packageName or importPath must be provided,
130 * because the reference refers to a module.
131 */
132 get: function () {
133 return this._memberReferences;
134 },
135 enumerable: false,
136 configurable: true
137 });
138 /**
139 * Generates the TSDoc representation of this declaration reference.
140 */
141 DocDeclarationReference.prototype.emitAsTsdoc = function () {
142 var stringBuilder = new StringBuilder();
143 // eslint-disable-next-line @typescript-eslint/no-use-before-define
144 var emitter = new TSDocEmitter();
145 emitter.renderDeclarationReference(stringBuilder, this);
146 return stringBuilder.toString();
147 };
148 /** @override */
149 DocDeclarationReference.prototype.onGetChildNodes = function () {
150 return __spreadArrays([
151 this._packageNameExcerpt,
152 this._importPathExcerpt,
153 this._importHashExcerpt,
154 this._spacingAfterImportHashExcerpt
155 ], this._memberReferences);
156 };
157 return DocDeclarationReference;
158}(DocNode));
159export { DocDeclarationReference };
160// Circular reference
161import { TSDocEmitter } from '../emitters/TSDocEmitter';
162//# sourceMappingURL=DocDeclarationReference.js.map
\No newline at end of file