1 | "use strict";
|
2 | var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
3 | if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
4 | if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
5 | return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
6 | };
|
7 | var _a, _Directives_CACHE;
|
8 | Object.defineProperty(exports, "__esModule", { value: true });
|
9 | exports.Directives = void 0;
|
10 | const ts = require("typescript");
|
11 | const jsii_diagnostic_1 = require("./jsii-diagnostic");
|
12 |
|
13 |
|
14 |
|
15 | class Directives {
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | static of(node, onDiagnostic) {
|
24 | const found = __classPrivateFieldGet(_a, _a, "f", _Directives_CACHE).get(node);
|
25 | if (found != null) {
|
26 | return found;
|
27 | }
|
28 | const directives = new _a(node, onDiagnostic);
|
29 | __classPrivateFieldGet(_a, _a, "f", _Directives_CACHE).set(node, directives);
|
30 | return directives;
|
31 | }
|
32 | constructor(node, onDiagnostic) {
|
33 | for (const tag of ts.getJSDocTags(node)) {
|
34 | switch (tag.tagName.text) {
|
35 | case 'internal':
|
36 | this.tsInternal ?? (this.tsInternal = tag);
|
37 | break;
|
38 | case 'jsii':
|
39 | const comments = getComments(tag);
|
40 | if (comments.length === 0) {
|
41 | onDiagnostic(jsii_diagnostic_1.JsiiDiagnostic.JSII_2000_MISSING_DIRECTIVE_ARGUMENT.create(tag));
|
42 | continue;
|
43 | }
|
44 | for (const { text, jsdocNode } of comments) {
|
45 | switch (text) {
|
46 | case 'ignore':
|
47 | this.ignore ?? (this.ignore = jsdocNode);
|
48 | break;
|
49 | default:
|
50 | onDiagnostic(jsii_diagnostic_1.JsiiDiagnostic.JSII_2999_UNKNOWN_DIRECTIVE.create(jsdocNode, text));
|
51 | break;
|
52 | }
|
53 | }
|
54 | break;
|
55 | default:
|
56 | }
|
57 | }
|
58 | }
|
59 | }
|
60 | exports.Directives = Directives;
|
61 | _a = Directives;
|
62 | _Directives_CACHE = { value: new WeakMap() };
|
63 | function getComments(tag) {
|
64 | if (tag.comment == null) {
|
65 | return [];
|
66 | }
|
67 | if (typeof tag.comment === 'string') {
|
68 | const text = tag.comment.trim();
|
69 | return text
|
70 | ? text.split(/[\n,]/).flatMap((line) => {
|
71 | line = line.trim();
|
72 | return line ? [{ text: line, jsdocNode: tag }] : [];
|
73 | })
|
74 | : [];
|
75 | }
|
76 |
|
77 | return tag.comment.flatMap((jsdocNode) => {
|
78 | let text;
|
79 | switch (jsdocNode.kind) {
|
80 | case ts.SyntaxKind.JSDocText:
|
81 | text = jsdocNode.text;
|
82 | break;
|
83 | case ts.SyntaxKind.JSDocLink:
|
84 | case ts.SyntaxKind.JSDocLinkCode:
|
85 | case ts.SyntaxKind.JSDocLinkPlain:
|
86 | text = jsdocNode.name
|
87 | ? `${jsdocNode.name.getText(jsdocNode.name.getSourceFile())}: ${jsdocNode.text}`
|
88 | : jsdocNode.text;
|
89 | break;
|
90 | }
|
91 | text = text.trim();
|
92 | return text ? [{ text, jsdocNode }] : [];
|
93 | });
|
94 | }
|
95 |
|
\ | No newline at end of file |