UNPKG

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