From a1df8f774fd81c389a10d2e44a3568d7f0647c67 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Mon, 24 Apr 2023 15:36:41 -0700 Subject: [PATCH] Expose getJSDocCommentsAndTags (#53627) --- src/compiler/utilities.ts | 24 ++++++++++++++++++- .../reference/api/tsserverlibrary.d.ts | 20 ++++++++++++++++ tests/baselines/reference/api/typescript.d.ts | 20 ++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index bc6882e5fbb..aa69702d062 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -4198,7 +4198,29 @@ export function canHaveJSDoc(node: Node): node is HasJSDoc { } } -/** @internal */ +/** + * This function checks multiple locations for JSDoc comments that apply to a host node. + * At each location, the whole comment may apply to the node, or only a specific tag in + * the comment. In the first case, location adds the entire {@link JSDoc} object. In the + * second case, it adds the applicable {@link JSDocTag}. + * + * For example, a JSDoc comment before a parameter adds the entire {@link JSDoc}. But a + * `@param` tag on the parent function only adds the {@link JSDocTag} for the `@param`. + * + * ```ts + * /** JSDoc will be returned for `a` *\/ + * const a = 0 + * /** + * * Entire JSDoc will be returned for `b` + * * @param c JSDocTag will be returned for `c` + * *\/ + * function b(/** JSDoc will be returned for `c` *\/ c) {} + * ``` + */ +export function getJSDocCommentsAndTags(hostNode: Node): readonly (JSDoc | JSDocTag)[]; +/** @internal separate signature so that stripInternal can remove noCache from the public API */ +// eslint-disable-next-line @typescript-eslint/unified-signatures +export function getJSDocCommentsAndTags(hostNode: Node, noCache?: boolean): readonly (JSDoc | JSDocTag)[]; export function getJSDocCommentsAndTags(hostNode: Node, noCache?: boolean): readonly (JSDoc | JSDocTag)[] { let result: (JSDoc | JSDocTag)[] | undefined; // Pull parameter comments from declaring function as well diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index b32da46bd2b..0eed80cc8a5 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -8817,6 +8817,26 @@ declare namespace ts { parent: ConstructorDeclaration; name: Identifier; }; + /** + * This function checks multiple locations for JSDoc comments that apply to a host node. + * At each location, the whole comment may apply to the node, or only a specific tag in + * the comment. In the first case, location adds the entire {@link JSDoc} object. In the + * second case, it adds the applicable {@link JSDocTag}. + * + * For example, a JSDoc comment before a parameter adds the entire {@link JSDoc}. But a + * `@param` tag on the parent function only adds the {@link JSDocTag} for the `@param`. + * + * ```ts + * /** JSDoc will be returned for `a` *\/ + * const a = 0 + * /** + * * Entire JSDoc will be returned for `b` + * * @param c JSDocTag will be returned for `c` + * *\/ + * function b(/** JSDoc will be returned for `c` *\/ c) {} + * ``` + */ + function getJSDocCommentsAndTags(hostNode: Node): readonly (JSDoc | JSDocTag)[]; /** @deprecated */ function createUnparsedSourceFile(text: string): UnparsedSource; /** @deprecated */ diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index e15b3491cfb..674c274fa09 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -4771,6 +4771,26 @@ declare namespace ts { parent: ConstructorDeclaration; name: Identifier; }; + /** + * This function checks multiple locations for JSDoc comments that apply to a host node. + * At each location, the whole comment may apply to the node, or only a specific tag in + * the comment. In the first case, location adds the entire {@link JSDoc} object. In the + * second case, it adds the applicable {@link JSDocTag}. + * + * For example, a JSDoc comment before a parameter adds the entire {@link JSDoc}. But a + * `@param` tag on the parent function only adds the {@link JSDocTag} for the `@param`. + * + * ```ts + * /** JSDoc will be returned for `a` *\/ + * const a = 0 + * /** + * * Entire JSDoc will be returned for `b` + * * @param c JSDocTag will be returned for `c` + * *\/ + * function b(/** JSDoc will be returned for `c` *\/ c) {} + * ``` + */ + function getJSDocCommentsAndTags(hostNode: Node): readonly (JSDoc | JSDocTag)[]; /** @deprecated */ function createUnparsedSourceFile(text: string): UnparsedSource; /** @deprecated */