UNPKG

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