1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.DocNodeManager = void 0;
|
4 | var StringChecks_1 = require("../parser/StringChecks");
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | var DocNodeManager = (function () {
|
14 | function DocNodeManager() {
|
15 | this._docNodeDefinitionsByKind = new Map();
|
16 | this._docNodeDefinitionsByConstructor = new Map();
|
17 | }
|
18 | |
19 |
|
20 |
|
21 |
|
22 | DocNodeManager.prototype.registerDocNodes = function (packageName, definitions) {
|
23 | var packageNameError = StringChecks_1.StringChecks.explainIfInvalidPackageName(packageName);
|
24 | if (packageNameError) {
|
25 | throw new Error('Invalid NPM package name: ' + packageNameError);
|
26 | }
|
27 | for (var _i = 0, definitions_1 = definitions; _i < definitions_1.length; _i++) {
|
28 | var definition = definitions_1[_i];
|
29 | if (!DocNodeManager._nodeKindRegExp.test(definition.docNodeKind)) {
|
30 | throw new Error("The DocNode kind " + JSON.stringify(definition.docNodeKind) + " is not a valid identifier." +
|
31 | " It must start with an underscore or letter, and be comprised of letters, numbers, and underscores");
|
32 | }
|
33 | var existingDefinition = this._docNodeDefinitionsByKind.get(definition.docNodeKind);
|
34 | if (existingDefinition !== undefined) {
|
35 | throw new Error("The DocNode kind \"" + definition.docNodeKind + "\" was already registered" +
|
36 | (" by " + existingDefinition.packageName));
|
37 | }
|
38 | existingDefinition = this._docNodeDefinitionsByConstructor.get(definition.constructor);
|
39 | if (existingDefinition !== undefined) {
|
40 | throw new Error("This DocNode constructor was already registered by " + existingDefinition.packageName +
|
41 | (" as " + existingDefinition.docNodeKind));
|
42 | }
|
43 | var newDefinition = {
|
44 | docNodeKind: definition.docNodeKind,
|
45 | constructor: definition.constructor,
|
46 | packageName: packageName,
|
47 | allowedChildKinds: new Set()
|
48 | };
|
49 | this._docNodeDefinitionsByKind.set(definition.docNodeKind, newDefinition);
|
50 | this._docNodeDefinitionsByConstructor.set(definition.constructor, newDefinition);
|
51 | }
|
52 | };
|
53 | /**
|
54 | * Reports an error if the specified DocNode kind has not been registered.
|
55 | */
|
56 | DocNodeManager.prototype.throwIfNotRegisteredKind = function (docNodeKind) {
|
57 | if (!this._docNodeDefinitionsByKind.has(docNodeKind)) {
|
58 | throw new Error("The DocNode kind \"" + docNodeKind + "\" was not registered with this TSDocConfiguration");
|
59 | }
|
60 | };
|
61 | |
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | DocNodeManager.prototype.registerAllowableChildren = function (parentKind, childKinds) {
|
70 | var parentDefinition = this._getDefinition(parentKind);
|
71 | for (var _i = 0, childKinds_1 = childKinds; _i < childKinds_1.length; _i++) {
|
72 | var childKind = childKinds_1[_i];
|
73 | this._getDefinition(childKind);
|
74 | parentDefinition.allowedChildKinds.add(childKind);
|
75 | }
|
76 | };
|
77 | |
78 |
|
79 |
|
80 |
|
81 | DocNodeManager.prototype.isAllowedChild = function (parentKind, childKind) {
|
82 | var parentDefinition = this._getDefinition(parentKind);
|
83 | return parentDefinition.allowedChildKinds.has(childKind);
|
84 | };
|
85 | DocNodeManager.prototype._getDefinition = function (docNodeKind) {
|
86 | var definition = this._docNodeDefinitionsByKind.get(docNodeKind);
|
87 | if (definition === undefined) {
|
88 | throw new Error("The DocNode kind \"" + docNodeKind + "\" was not registered with this TSDocConfiguration");
|
89 | }
|
90 | return definition;
|
91 | };
|
92 |
|
93 |
|
94 |
|
95 | DocNodeManager._nodeKindRegExp = /^[_a-z][_a-z0-9]*$/i;
|
96 | return DocNodeManager;
|
97 | }());
|
98 | exports.DocNodeManager = DocNodeManager;
|
99 |
|
\ | No newline at end of file |