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7B,KAAK,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC;YACjC,KAAK,EAAE,CAAC,UAAU,CAAC,cAAc;gBAC/B,IAAI,GAAG,SAAS,CAAC,IAAI;oBACnB,CAAC,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,KAAK,SAAS,CAAC,IAAI,EAAE;oBAChF,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC;gBACnB,MAAM;QACV,CAAC;QACD,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import * as ts from 'typescript';\nimport { JsiiDiagnostic } from './jsii-diagnostic';\n\n/**\n * TSDoc-style directives that can be attached to a symbol.\n */\nexport class Directives {\n /**\n * Obtains the `Directives` for a given TypeScript AST node.\n *\n * @param node the node for which directives are requested.\n * @param onDiagnostic a callback invoked whenever a diagnostic message is\n * emitted when parsing directives.\n */\n public static of(node: ts.Node, onDiagnostic: (diag: JsiiDiagnostic) => void): Directives {\n const found = Directives.#CACHE.get(node);\n if (found != null) {\n return found;\n }\n\n const directives = new Directives(node, onDiagnostic);\n Directives.#CACHE.set(node, directives);\n return directives;\n }\n\n static readonly #CACHE = new WeakMap<ts.Node, Directives>();\n\n /** Whether the node has the `@internal` JSDoc tag. */\n public readonly tsInternal?: ts.JSDocTag;\n /** Whether the node has the `@jsii ignore` directive set. */\n public readonly ignore?: ts.JSDocComment | ts.JSDocTag;\n /** Whether the node has the `@jsii struct` directive set. */\n public readonly struct?: ts.JSDocComment | ts.JSDocTag;\n\n private constructor(node: ts.Node, onDiagnostic: (diag: JsiiDiagnostic) => void) {\n for (const tag of ts.getJSDocTags(node)) {\n switch (tag.tagName.text) {\n case 'internal':\n this.tsInternal ??= tag;\n break;\n case 'jsii':\n const comments = getComments(tag);\n if (comments.length === 0) {\n onDiagnostic(JsiiDiagnostic.JSII_2000_MISSING_DIRECTIVE_ARGUMENT.create(tag));\n continue;\n }\n for (const { text, jsdocNode } of comments) {\n switch (text) {\n case 'ignore':\n this.ignore ??= jsdocNode;\n break;\n default:\n onDiagnostic(JsiiDiagnostic.JSII_2999_UNKNOWN_DIRECTIVE.create(jsdocNode, text));\n break;\n }\n }\n break;\n default: // Ignore\n }\n }\n }\n}\n\nfunction getComments(tag: ts.JSDocTag): Comment[] {\n if (tag.comment == null) {\n return [];\n }\n\n if (typeof tag.comment === 'string') {\n const text = tag.comment.trim();\n return text\n ? text.split(/[\\n,]/).flatMap((line) => {\n line = line.trim();\n return line ? [{ text: line, jsdocNode: tag }] : [];\n })\n : [];\n }\n\n // Possible per the type signature in the compiler, however not sure in which conditions.\n return tag.comment.flatMap((jsdocNode): Comment[] => {\n let text: string;\n switch (jsdocNode.kind) {\n case ts.SyntaxKind.JSDocText:\n text = jsdocNode.text;\n break;\n case ts.SyntaxKind.JSDocLink:\n case ts.SyntaxKind.JSDocLinkCode:\n case ts.SyntaxKind.JSDocLinkPlain:\n text = jsdocNode.name\n ? `${jsdocNode.name.getText(jsdocNode.name.getSourceFile())}: ${jsdocNode.text}`\n : jsdocNode.text;\n break;\n }\n text = text.trim();\n return text ? [{ text, jsdocNode }] : [];\n });\n}\n\ninterface Comment {\n readonly text: string;\n readonly jsdocNode: ts.JSDocComment | ts.JSDocTag;\n}\n"]}
\No newline at end of file