1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | let REFLECTION_ID = 0;
|
4 | function resetReflectionID() {
|
5 | REFLECTION_ID = 0;
|
6 | }
|
7 | exports.resetReflectionID = resetReflectionID;
|
8 | var ReflectionKind;
|
9 | (function (ReflectionKind) {
|
10 | ReflectionKind[ReflectionKind["Global"] = 0] = "Global";
|
11 | ReflectionKind[ReflectionKind["ExternalModule"] = 1] = "ExternalModule";
|
12 | ReflectionKind[ReflectionKind["Module"] = 2] = "Module";
|
13 | ReflectionKind[ReflectionKind["Enum"] = 4] = "Enum";
|
14 | ReflectionKind[ReflectionKind["EnumMember"] = 16] = "EnumMember";
|
15 | ReflectionKind[ReflectionKind["Variable"] = 32] = "Variable";
|
16 | ReflectionKind[ReflectionKind["Function"] = 64] = "Function";
|
17 | ReflectionKind[ReflectionKind["Class"] = 128] = "Class";
|
18 | ReflectionKind[ReflectionKind["Interface"] = 256] = "Interface";
|
19 | ReflectionKind[ReflectionKind["Constructor"] = 512] = "Constructor";
|
20 | ReflectionKind[ReflectionKind["Property"] = 1024] = "Property";
|
21 | ReflectionKind[ReflectionKind["Method"] = 2048] = "Method";
|
22 | ReflectionKind[ReflectionKind["CallSignature"] = 4096] = "CallSignature";
|
23 | ReflectionKind[ReflectionKind["IndexSignature"] = 8192] = "IndexSignature";
|
24 | ReflectionKind[ReflectionKind["ConstructorSignature"] = 16384] = "ConstructorSignature";
|
25 | ReflectionKind[ReflectionKind["Parameter"] = 32768] = "Parameter";
|
26 | ReflectionKind[ReflectionKind["TypeLiteral"] = 65536] = "TypeLiteral";
|
27 | ReflectionKind[ReflectionKind["TypeParameter"] = 131072] = "TypeParameter";
|
28 | ReflectionKind[ReflectionKind["Accessor"] = 262144] = "Accessor";
|
29 | ReflectionKind[ReflectionKind["GetSignature"] = 524288] = "GetSignature";
|
30 | ReflectionKind[ReflectionKind["SetSignature"] = 1048576] = "SetSignature";
|
31 | ReflectionKind[ReflectionKind["ObjectLiteral"] = 2097152] = "ObjectLiteral";
|
32 | ReflectionKind[ReflectionKind["TypeAlias"] = 4194304] = "TypeAlias";
|
33 | ReflectionKind[ReflectionKind["Event"] = 8388608] = "Event";
|
34 | ReflectionKind[ReflectionKind["ClassOrInterface"] = 384] = "ClassOrInterface";
|
35 | ReflectionKind[ReflectionKind["VariableOrProperty"] = 1056] = "VariableOrProperty";
|
36 | ReflectionKind[ReflectionKind["FunctionOrMethod"] = 2112] = "FunctionOrMethod";
|
37 | ReflectionKind[ReflectionKind["SomeSignature"] = 1601536] = "SomeSignature";
|
38 | ReflectionKind[ReflectionKind["SomeModule"] = 3] = "SomeModule";
|
39 | ReflectionKind[ReflectionKind["SomeType"] = 4391168] = "SomeType";
|
40 | ReflectionKind[ReflectionKind["SomeValue"] = 2097248] = "SomeValue";
|
41 | })(ReflectionKind = exports.ReflectionKind || (exports.ReflectionKind = {}));
|
42 | var ReflectionFlag;
|
43 | (function (ReflectionFlag) {
|
44 | ReflectionFlag[ReflectionFlag["None"] = 0] = "None";
|
45 | ReflectionFlag[ReflectionFlag["Private"] = 1] = "Private";
|
46 | ReflectionFlag[ReflectionFlag["Protected"] = 2] = "Protected";
|
47 | ReflectionFlag[ReflectionFlag["Public"] = 4] = "Public";
|
48 | ReflectionFlag[ReflectionFlag["Static"] = 8] = "Static";
|
49 | ReflectionFlag[ReflectionFlag["Exported"] = 16] = "Exported";
|
50 | ReflectionFlag[ReflectionFlag["ExportAssignment"] = 32] = "ExportAssignment";
|
51 | ReflectionFlag[ReflectionFlag["External"] = 64] = "External";
|
52 | ReflectionFlag[ReflectionFlag["Optional"] = 128] = "Optional";
|
53 | ReflectionFlag[ReflectionFlag["DefaultValue"] = 256] = "DefaultValue";
|
54 | ReflectionFlag[ReflectionFlag["Rest"] = 512] = "Rest";
|
55 | ReflectionFlag[ReflectionFlag["ConstructorProperty"] = 1024] = "ConstructorProperty";
|
56 | ReflectionFlag[ReflectionFlag["Abstract"] = 2048] = "Abstract";
|
57 | ReflectionFlag[ReflectionFlag["Const"] = 4096] = "Const";
|
58 | ReflectionFlag[ReflectionFlag["Let"] = 8192] = "Let";
|
59 | })(ReflectionFlag = exports.ReflectionFlag || (exports.ReflectionFlag = {}));
|
60 | const relevantFlags = [
|
61 | ReflectionFlag.Private,
|
62 | ReflectionFlag.Protected,
|
63 | ReflectionFlag.Static,
|
64 | ReflectionFlag.ExportAssignment,
|
65 | ReflectionFlag.Optional,
|
66 | ReflectionFlag.DefaultValue,
|
67 | ReflectionFlag.Rest,
|
68 | ReflectionFlag.Abstract,
|
69 | ReflectionFlag.Let,
|
70 | ReflectionFlag.Const
|
71 | ];
|
72 | class ReflectionFlags extends Array {
|
73 | constructor() {
|
74 | super(...arguments);
|
75 | this.flags = ReflectionFlag.None;
|
76 | }
|
77 | hasFlag(flag) {
|
78 | return (flag & this.flags) !== 0;
|
79 | }
|
80 | get isPrivate() {
|
81 | return this.hasFlag(ReflectionFlag.Private);
|
82 | }
|
83 | get isProtected() {
|
84 | return this.hasFlag(ReflectionFlag.Protected);
|
85 | }
|
86 | get isPublic() {
|
87 | return this.hasFlag(ReflectionFlag.Public);
|
88 | }
|
89 | get isStatic() {
|
90 | return this.hasFlag(ReflectionFlag.Static);
|
91 | }
|
92 | get isExported() {
|
93 | return this.hasFlag(ReflectionFlag.Exported);
|
94 | }
|
95 | get isExternal() {
|
96 | return this.hasFlag(ReflectionFlag.External);
|
97 | }
|
98 | get isOptional() {
|
99 | return this.hasFlag(ReflectionFlag.Optional);
|
100 | }
|
101 | get isRest() {
|
102 | return this.hasFlag(ReflectionFlag.Rest);
|
103 | }
|
104 | get hasExportAssignment() {
|
105 | return this.hasFlag(ReflectionFlag.ExportAssignment);
|
106 | }
|
107 | get isConstructorProperty() {
|
108 | return this.hasFlag(ReflectionFlag.ConstructorProperty);
|
109 | }
|
110 | get isAbstract() {
|
111 | return this.hasFlag(ReflectionFlag.Abstract);
|
112 | }
|
113 | get isConst() {
|
114 | return this.hasFlag(ReflectionFlag.Const);
|
115 | }
|
116 | get isLet() {
|
117 | return this.hasFlag(ReflectionFlag.Let);
|
118 | }
|
119 | setFlag(flag, set) {
|
120 | switch (flag) {
|
121 | case ReflectionFlag.Private:
|
122 | this.setSingleFlag(ReflectionFlag.Private, set);
|
123 | if (set) {
|
124 | this.setFlag(ReflectionFlag.Protected, false);
|
125 | this.setFlag(ReflectionFlag.Public, false);
|
126 | }
|
127 | break;
|
128 | case ReflectionFlag.Protected:
|
129 | this.setSingleFlag(ReflectionFlag.Protected, set);
|
130 | if (set) {
|
131 | this.setFlag(ReflectionFlag.Private, false);
|
132 | this.setFlag(ReflectionFlag.Public, false);
|
133 | }
|
134 | break;
|
135 | case ReflectionFlag.Public:
|
136 | this.setSingleFlag(ReflectionFlag.Public, set);
|
137 | if (set) {
|
138 | this.setFlag(ReflectionFlag.Private, false);
|
139 | this.setFlag(ReflectionFlag.Protected, false);
|
140 | }
|
141 | break;
|
142 | case ReflectionFlag.Const:
|
143 | case ReflectionFlag.Let:
|
144 | this.setSingleFlag(flag, set);
|
145 | this.setSingleFlag((ReflectionFlag.Let | ReflectionFlag.Const) ^ flag, !set);
|
146 | default:
|
147 | this.setSingleFlag(flag, set);
|
148 | }
|
149 | }
|
150 | setSingleFlag(flag, set) {
|
151 | const name = ReflectionFlag[flag].replace(/(.)([A-Z])/g, (m, a, b) => a + ' ' + b.toLowerCase());
|
152 | if (!set && this.hasFlag(flag)) {
|
153 | if (relevantFlags.includes(flag)) {
|
154 | this.splice(this.indexOf(name), 1);
|
155 | }
|
156 | this.flags ^= flag;
|
157 | }
|
158 | else if (set && !this.hasFlag(flag)) {
|
159 | if (relevantFlags.includes(flag)) {
|
160 | this.push(name);
|
161 | }
|
162 | this.flags |= flag;
|
163 | }
|
164 | }
|
165 | }
|
166 | exports.ReflectionFlags = ReflectionFlags;
|
167 | var TraverseProperty;
|
168 | (function (TraverseProperty) {
|
169 | TraverseProperty[TraverseProperty["Children"] = 0] = "Children";
|
170 | TraverseProperty[TraverseProperty["Parameters"] = 1] = "Parameters";
|
171 | TraverseProperty[TraverseProperty["TypeLiteral"] = 2] = "TypeLiteral";
|
172 | TraverseProperty[TraverseProperty["TypeParameter"] = 3] = "TypeParameter";
|
173 | TraverseProperty[TraverseProperty["Signatures"] = 4] = "Signatures";
|
174 | TraverseProperty[TraverseProperty["IndexSignature"] = 5] = "IndexSignature";
|
175 | TraverseProperty[TraverseProperty["GetSignature"] = 6] = "GetSignature";
|
176 | TraverseProperty[TraverseProperty["SetSignature"] = 7] = "SetSignature";
|
177 | })(TraverseProperty = exports.TraverseProperty || (exports.TraverseProperty = {}));
|
178 | class Reflection {
|
179 | constructor(name, kind, parent) {
|
180 | this.name = '';
|
181 | this.flags = new ReflectionFlags();
|
182 | this.id = REFLECTION_ID++;
|
183 | this.parent = parent;
|
184 | this.name = name;
|
185 | this.originalName = name;
|
186 | this.kind = kind;
|
187 | }
|
188 | kindOf(kind) {
|
189 | const kindArray = Array.isArray(kind) ? kind : [kind];
|
190 | return kindArray.some(kind => (this.kind & kind) !== 0);
|
191 | }
|
192 | getFullName(separator = '.') {
|
193 | if (this.parent && !this.parent.isProject()) {
|
194 | return this.parent.getFullName(separator) + separator + this.name;
|
195 | }
|
196 | else {
|
197 | return this.name;
|
198 | }
|
199 | }
|
200 | setFlag(flag, value = true) {
|
201 | this.flags.setFlag(flag, value);
|
202 | }
|
203 | getAlias() {
|
204 | if (!this._alias) {
|
205 | let alias = this.name.replace(/[^a-z0-9]/gi, '_').toLowerCase();
|
206 | if (alias === '') {
|
207 | alias = 'reflection-' + this.id;
|
208 | }
|
209 | let target = this;
|
210 | while (target.parent && !target.parent.isProject() && !target.hasOwnDocument) {
|
211 | target = target.parent;
|
212 | }
|
213 | if (!target._aliases) {
|
214 | target._aliases = [];
|
215 | }
|
216 | let suffix = '', index = 0;
|
217 | while (target._aliases.includes(alias + suffix)) {
|
218 | suffix = '-' + (++index).toString();
|
219 | }
|
220 | alias += suffix;
|
221 | target._aliases.push(alias);
|
222 | this._alias = alias;
|
223 | }
|
224 | return this._alias;
|
225 | }
|
226 | hasComment() {
|
227 | return this.comment ? this.comment.hasVisibleComponent() : false;
|
228 | }
|
229 | hasGetterOrSetter() {
|
230 | return false;
|
231 | }
|
232 | getChildByName(arg) {
|
233 | const names = Array.isArray(arg) ? arg : arg.split('.');
|
234 | const name = names[0];
|
235 | let result;
|
236 | this.traverse((child) => {
|
237 | if (child.name === name) {
|
238 | if (names.length <= 1) {
|
239 | result = child;
|
240 | }
|
241 | else {
|
242 | result = child.getChildByName(names.slice(1));
|
243 | }
|
244 | return false;
|
245 | }
|
246 | });
|
247 | return result;
|
248 | }
|
249 | isProject() {
|
250 | return false;
|
251 | }
|
252 | findReflectionByName(arg) {
|
253 | const names = Array.isArray(arg) ? arg : arg.split('.');
|
254 | const reflection = this.getChildByName(names);
|
255 | if (reflection) {
|
256 | return reflection;
|
257 | }
|
258 | else if (this.parent) {
|
259 | return this.parent.findReflectionByName(names);
|
260 | }
|
261 | }
|
262 | traverse(callback) { }
|
263 | toObject() {
|
264 | const result = {
|
265 | id: this.id,
|
266 | name: this.name,
|
267 | kind: this.kind,
|
268 | kindString: this.kindString,
|
269 | flags: {}
|
270 | };
|
271 | if (this.originalName !== this.name) {
|
272 | result.originalName = this.originalName;
|
273 | }
|
274 | if (this.comment) {
|
275 | result.comment = this.comment.toObject();
|
276 | }
|
277 | Object.getOwnPropertyNames(ReflectionFlags.prototype).forEach(name => {
|
278 | const descriptor = Object.getOwnPropertyDescriptor(ReflectionFlags.prototype, name);
|
279 | if (typeof descriptor.get === 'function' && this.flags[name] === true) {
|
280 | result.flags[name] = true;
|
281 | }
|
282 | });
|
283 | if (this.decorates) {
|
284 | result.decorates = this.decorates.map((type) => type.toObject());
|
285 | }
|
286 | if (this.decorators) {
|
287 | result.decorators = this.decorators.map((decorator) => {
|
288 | const result = { name: decorator.name };
|
289 | if (decorator.type) {
|
290 | result.type = decorator.type.toObject();
|
291 | }
|
292 | if (decorator.arguments) {
|
293 | result.arguments = decorator.arguments;
|
294 | }
|
295 | return result;
|
296 | });
|
297 | }
|
298 | this.traverse((child, property) => {
|
299 | if (property === TraverseProperty.TypeLiteral) {
|
300 | return;
|
301 | }
|
302 | let name = TraverseProperty[property];
|
303 | name = name.substr(0, 1).toLowerCase() + name.substr(1);
|
304 | if (!result[name]) {
|
305 | result[name] = [];
|
306 | }
|
307 | result[name].push(child.toObject());
|
308 | });
|
309 | return result;
|
310 | }
|
311 | toString() {
|
312 | return ReflectionKind[this.kind] + ' ' + this.name;
|
313 | }
|
314 | toStringHierarchy(indent = '') {
|
315 | const lines = [indent + this.toString()];
|
316 | indent += ' ';
|
317 | this.traverse((child) => {
|
318 | lines.push(child.toStringHierarchy(indent));
|
319 | });
|
320 | return lines.join('\n');
|
321 | }
|
322 | }
|
323 | exports.Reflection = Reflection;
|
324 |
|
\ | No newline at end of file |