From be7be5955bcafc9b27359dca0083d46fd58b6bd7 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 6 Sep 2017 09:41:05 -0700 Subject: [PATCH] Make getJSDocTags public too --- src/compiler/utilities.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 78eacee7d22..1b19fc738e8 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1502,16 +1502,7 @@ namespace ts { return getJSDocCommentsAndTags(node); } - export function getJSDocTags(node: Node): ReadonlyArray | undefined { - let tags = node.jsDocCache; - // If cache is 'null', that means we did the work of searching for JSDoc tags and came up with nothing. - if (tags === undefined) { - node.jsDocCache = tags = flatMap(getJSDocCommentsAndTags(node), j => isJSDoc(j) ? j.tags : j); - } - return tags; - } - - function getJSDocCommentsAndTags(node: Node): (JSDoc | JSDocTag)[] { + export function getJSDocCommentsAndTags(node: Node): (JSDoc | JSDocTag)[] { let result: Array | undefined; getJSDocCommentsAndTagsWorker(node); return result || emptyArray; @@ -4023,11 +4014,22 @@ namespace ts { return returnTag && returnTag.typeExpression && returnTag.typeExpression.type; } - /* Get the first JSDoc tag of a specified kind, or undefined if not present. */ + /** Get all JSDoc tags related to a node, including those on parent nodes. */ + export function getJSDocTags(node: Node): ReadonlyArray | undefined { + let tags = node.jsDocCache; + // If cache is 'null', that means we did the work of searching for JSDoc tags and came up with nothing. + if (tags === undefined) { + node.jsDocCache = tags = flatMap(getJSDocCommentsAndTags(node), j => isJSDoc(j) ? j.tags : j); + } + return tags; + } + + /** Get the first JSDoc tag of a specified kind, or undefined if not present. */ function getFirstJSDocTag(node: Node, kind: SyntaxKind): JSDocTag | undefined { const tags = getJSDocTags(node); return find(tags, doc => doc.kind === kind); } + } // Simple node tests of the form `node.kind === SyntaxKind.Foo`.