Skip to content

Commit a1df8f7

Browse files
authored
Expose getJSDocCommentsAndTags (#53627)
1 parent a177af1 commit a1df8f7

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

src/compiler/utilities.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -4198,7 +4198,29 @@ export function canHaveJSDoc(node: Node): node is HasJSDoc {
41984198
}
41994199
}
42004200

4201-
/** @internal */
4201+
/**
4202+
* This function checks multiple locations for JSDoc comments that apply to a host node.
4203+
* At each location, the whole comment may apply to the node, or only a specific tag in
4204+
* the comment. In the first case, location adds the entire {@link JSDoc} object. In the
4205+
* second case, it adds the applicable {@link JSDocTag}.
4206+
*
4207+
* For example, a JSDoc comment before a parameter adds the entire {@link JSDoc}. But a
4208+
* `@param` tag on the parent function only adds the {@link JSDocTag} for the `@param`.
4209+
*
4210+
* ```ts
4211+
* /** JSDoc will be returned for `a` *\/
4212+
* const a = 0
4213+
* /**
4214+
* * Entire JSDoc will be returned for `b`
4215+
* * @param c JSDocTag will be returned for `c`
4216+
* *\/
4217+
* function b(/** JSDoc will be returned for `c` *\/ c) {}
4218+
* ```
4219+
*/
4220+
export function getJSDocCommentsAndTags(hostNode: Node): readonly (JSDoc | JSDocTag)[];
4221+
/** @internal separate signature so that stripInternal can remove noCache from the public API */
4222+
// eslint-disable-next-line @typescript-eslint/unified-signatures
4223+
export function getJSDocCommentsAndTags(hostNode: Node, noCache?: boolean): readonly (JSDoc | JSDocTag)[];
42024224
export function getJSDocCommentsAndTags(hostNode: Node, noCache?: boolean): readonly (JSDoc | JSDocTag)[] {
42034225
let result: (JSDoc | JSDocTag)[] | undefined;
42044226
// Pull parameter comments from declaring function as well

tests/baselines/reference/api/tsserverlibrary.d.ts

+20
Original file line numberDiff line numberDiff line change
@@ -8817,6 +8817,26 @@ declare namespace ts {
88178817
parent: ConstructorDeclaration;
88188818
name: Identifier;
88198819
};
8820+
/**
8821+
* This function checks multiple locations for JSDoc comments that apply to a host node.
8822+
* At each location, the whole comment may apply to the node, or only a specific tag in
8823+
* the comment. In the first case, location adds the entire {@link JSDoc} object. In the
8824+
* second case, it adds the applicable {@link JSDocTag}.
8825+
*
8826+
* For example, a JSDoc comment before a parameter adds the entire {@link JSDoc}. But a
8827+
* `@param` tag on the parent function only adds the {@link JSDocTag} for the `@param`.
8828+
*
8829+
* ```ts
8830+
* /** JSDoc will be returned for `a` *\/
8831+
* const a = 0
8832+
* /**
8833+
* * Entire JSDoc will be returned for `b`
8834+
* * @param c JSDocTag will be returned for `c`
8835+
* *\/
8836+
* function b(/** JSDoc will be returned for `c` *\/ c) {}
8837+
* ```
8838+
*/
8839+
function getJSDocCommentsAndTags(hostNode: Node): readonly (JSDoc | JSDocTag)[];
88208840
/** @deprecated */
88218841
function createUnparsedSourceFile(text: string): UnparsedSource;
88228842
/** @deprecated */

tests/baselines/reference/api/typescript.d.ts

+20
Original file line numberDiff line numberDiff line change
@@ -4771,6 +4771,26 @@ declare namespace ts {
47714771
parent: ConstructorDeclaration;
47724772
name: Identifier;
47734773
};
4774+
/**
4775+
* This function checks multiple locations for JSDoc comments that apply to a host node.
4776+
* At each location, the whole comment may apply to the node, or only a specific tag in
4777+
* the comment. In the first case, location adds the entire {@link JSDoc} object. In the
4778+
* second case, it adds the applicable {@link JSDocTag}.
4779+
*
4780+
* For example, a JSDoc comment before a parameter adds the entire {@link JSDoc}. But a
4781+
* `@param` tag on the parent function only adds the {@link JSDocTag} for the `@param`.
4782+
*
4783+
* ```ts
4784+
* /** JSDoc will be returned for `a` *\/
4785+
* const a = 0
4786+
* /**
4787+
* * Entire JSDoc will be returned for `b`
4788+
* * @param c JSDocTag will be returned for `c`
4789+
* *\/
4790+
* function b(/** JSDoc will be returned for `c` *\/ c) {}
4791+
* ```
4792+
*/
4793+
function getJSDocCommentsAndTags(hostNode: Node): readonly (JSDoc | JSDocTag)[];
47744794
/** @deprecated */
47754795
function createUnparsedSourceFile(text: string): UnparsedSource;
47764796
/** @deprecated */

0 commit comments

Comments
 (0)