UNPKG

4.88 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})();
15Object.defineProperty(exports, "__esModule", { value: true });
16exports.DocMemberIdentifier = void 0;
17var DocNode_1 = require("./DocNode");
18var StringChecks_1 = require("../parser/StringChecks");
19var DocExcerpt_1 = require("./DocExcerpt");
20/**
21 * A member identifier is part of a {@link DocMemberReference}.
22 */
23var DocMemberIdentifier = /** @class */ (function (_super) {
24 __extends(DocMemberIdentifier, _super);
25 /**
26 * Don't call this directly. Instead use {@link TSDocParser}
27 * @internal
28 */
29 function DocMemberIdentifier(parameters) {
30 var _this = _super.call(this, parameters) || this;
31 if (DocNode_1.DocNode.isParsedParameters(parameters)) {
32 if (parameters.leftQuoteExcerpt) {
33 _this._leftQuoteExcerpt = new DocExcerpt_1.DocExcerpt({
34 configuration: _this.configuration,
35 excerptKind: DocExcerpt_1.ExcerptKind.MemberIdentifier_LeftQuote,
36 content: parameters.leftQuoteExcerpt
37 });
38 }
39 _this._identifierExcerpt = new DocExcerpt_1.DocExcerpt({
40 configuration: _this.configuration,
41 excerptKind: DocExcerpt_1.ExcerptKind.MemberIdentifier_Identifier,
42 content: parameters.identifierExcerpt
43 });
44 if (parameters.rightQuoteExcerpt) {
45 _this._rightQuoteExcerpt = new DocExcerpt_1.DocExcerpt({
46 configuration: _this.configuration,
47 excerptKind: DocExcerpt_1.ExcerptKind.MemberIdentifier_RightQuote,
48 content: parameters.rightQuoteExcerpt
49 });
50 }
51 }
52 else {
53 _this._identifier = parameters.identifier;
54 }
55 return _this;
56 }
57 /**
58 * Tests whether the input string can be used without quotes as a member identifier in a declaration reference.
59 * If not, {@link DocMemberIdentifier.hasQuotes} will be required.
60 *
61 * @remarks
62 * In order to be used without quotes, the string must follow the identifier syntax for ECMAScript / TypeScript,
63 * and it must not be one of the reserved words used for system selectors (such as `instance`, `static`,
64 * `constructor`, etc).
65 */
66 DocMemberIdentifier.isValidIdentifier = function (identifier) {
67 return !StringChecks_1.StringChecks.explainIfInvalidUnquotedMemberIdentifier(identifier);
68 };
69 Object.defineProperty(DocMemberIdentifier.prototype, "kind", {
70 /** @override */
71 get: function () {
72 return DocNode_1.DocNodeKind.MemberIdentifier;
73 },
74 enumerable: false,
75 configurable: true
76 });
77 Object.defineProperty(DocMemberIdentifier.prototype, "identifier", {
78 /**
79 * The identifier string without any quote encoding.
80 *
81 * @remarks
82 * If the value is not a valid ECMAScript identifier, it will be quoted as a
83 * string literal during rendering.
84 */
85 get: function () {
86 if (this._identifier === undefined) {
87 this._identifier = this._identifierExcerpt.content.toString();
88 }
89 return this._identifier;
90 },
91 enumerable: false,
92 configurable: true
93 });
94 Object.defineProperty(DocMemberIdentifier.prototype, "hasQuotes", {
95 /**
96 * Returns true if the identifier will be rendered as a quoted string literal
97 * instead of as a programming language identifier. This is required if the
98 * `identifier` property is not a valid ECMAScript identifier.
99 */
100 get: function () {
101 if (this._identifierExcerpt) {
102 return !!this._leftQuoteExcerpt;
103 }
104 else {
105 return !DocMemberIdentifier.isValidIdentifier(this.identifier);
106 }
107 },
108 enumerable: false,
109 configurable: true
110 });
111 /** @override */
112 DocMemberIdentifier.prototype.onGetChildNodes = function () {
113 return [this._leftQuoteExcerpt, this._identifierExcerpt, this._rightQuoteExcerpt];
114 };
115 return DocMemberIdentifier;
116}(DocNode_1.DocNode));
117exports.DocMemberIdentifier = DocMemberIdentifier;
118//# sourceMappingURL=DocMemberIdentifier.js.map
\No newline at end of file