From 41937a044d60b278f864d8ae33a2df18e18c7aa0 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Wed, 18 Nov 2026 14:16:46 -0800 Subject: [PATCH 1/3] Export getJSDocParameterTags Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/jsdoc.ts | 3 +- packages/typescript/test/sync/ast.test.ts | 43 +++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/packages/typescript/src/ast/jsdoc.ts b/packages/typescript/src/ast/jsdoc.ts index 6b6370a8e7022..edaa24c95eea4 100644 --- a/packages/typescript/src/ast/jsdoc.ts +++ b/packages/typescript/src/ast/jsdoc.ts @@ -127,7 +127,8 @@ function filterOwnedJSDocTags(hostNode: Node, comments: JSDoc[]): (JSDoc | JSDoc return result; } -function getJSDocParameterTags(param: ParameterDeclaration): JSDocParameterTag[] { +/** Gets the JSDoc parameter tags that match a parameter declaration. */ +export function getJSDocParameterTags(param: ParameterDeclaration): readonly JSDocParameterTag[] { const result: JSDocParameterTag[] = []; const name = param.name; const parentTags = getJSDocTags(param.parent); diff --git a/packages/typescript/test/sync/ast.test.ts b/packages/typescript/test/sync/ast.test.ts index d3e33409b6cbf..85934f48e5daf 100644 --- a/packages/typescript/test/sync/ast.test.ts +++ b/packages/typescript/test/sync/ast.test.ts @@ -122,6 +122,49 @@ test("index signatures allow an omitted type", () => { assert.strictEqual(declaration.members.length, 2); }); +describe("JSDoc helpers", { concurrency }, () => { + test("getJSDocParameterTags matches identifiers by name", () => { + using api = spawnAPI(); + const source = api.createSourceFile( + "/parameters.ts", + `/** + * @param second the second parameter + * @param first the first parameter + * @param first another description + * @param first.property a nested property + */ +function f(first: object, second: string, undocumented: number) {} +`, + ).sourceFile; + const declaration = source.statements[0]; + assert.ok(astModule.isFunctionDeclaration(declaration)); + const tags = astModule.getJSDocTags(declaration).filter(astModule.isJSDocParameterTag); + assert.deepStrictEqual(astModule.getJSDocParameterTags(declaration.parameters[0]), [tags[1], tags[2]]); + assert.deepStrictEqual(astModule.getJSDocParameterTags(declaration.parameters[1]), [tags[0]]); + assert.deepStrictEqual(astModule.getJSDocParameterTags(declaration.parameters[2]), []); + }); + + test("getJSDocParameterTags matches binding patterns by position", () => { + using api = spawnAPI(); + const source = api.createSourceFile( + "/bindings.js", + `/** + * @param {string} named a named parameter + * @param {object} options an object parameter + * @param {Array} entries an array parameter + */ +function f(named, { value }, [entry], { undocumented }) {} +`, + ).sourceFile; + const declaration = source.statements[0]; + assert.ok(astModule.isFunctionDeclaration(declaration)); + const tags = astModule.getJSDocTags(declaration).filter(astModule.isJSDocParameterTag); + assert.deepStrictEqual(astModule.getJSDocParameterTags(declaration.parameters[1]), [tags[1]]); + assert.deepStrictEqual(astModule.getJSDocParameterTags(declaration.parameters[2]), [tags[2]]); + assert.deepStrictEqual(astModule.getJSDocParameterTags(declaration.parameters[3]), []); + }); +}); + describe("AST property contracts", { concurrency }, () => { test("JSDoc signatures expose tags rather than declaration children", () => { using api = spawnAPI(); From 5dc833e1a3384b87cf676a99509a62e490840346 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Wed, 18 Nov 2026 14:17:15 -0800 Subject: [PATCH 2/3] Export getJSDocTypeParameterTags Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/jsdoc.ts | 3 ++- packages/typescript/test/sync/ast.test.ts | 24 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/typescript/src/ast/jsdoc.ts b/packages/typescript/src/ast/jsdoc.ts index edaa24c95eea4..d010334f8026d 100644 --- a/packages/typescript/src/ast/jsdoc.ts +++ b/packages/typescript/src/ast/jsdoc.ts @@ -153,7 +153,8 @@ export function getJSDocParameterTags(param: ParameterDeclaration): readonly JSD return result; } -function getJSDocTypeParameterTags(typeParam: TypeParameterDeclaration): JSDocTemplateTag[] { +/** Gets the JSDoc template tags that declare a type parameter's name. */ +export function getJSDocTypeParameterTags(typeParam: TypeParameterDeclaration): readonly JSDocTemplateTag[] { const result: JSDocTemplateTag[] = []; const name = typeParam.name.text; for (const tag of getJSDocTags(typeParam.parent)) { diff --git a/packages/typescript/test/sync/ast.test.ts b/packages/typescript/test/sync/ast.test.ts index 85934f48e5daf..6adaa1f093245 100644 --- a/packages/typescript/test/sync/ast.test.ts +++ b/packages/typescript/test/sync/ast.test.ts @@ -144,6 +144,30 @@ function f(first: object, second: string, undocumented: number) {} assert.deepStrictEqual(astModule.getJSDocParameterTags(declaration.parameters[2]), []); }); + test("getJSDocTypeParameterTags matches names within template tags", () => { + using api = spawnAPI(); + const source = api.createSourceFile( + "/templates.ts", + `/** + * @template U, V shared description + * @template T the first description + * @template T another description + * @template Other an unrelated type parameter + */ +function f() {} +`, + ).sourceFile; + const declaration = source.statements[0]; + assert.ok(astModule.isFunctionDeclaration(declaration)); + const parameters = declaration.typeParameters; + assert.ok(parameters); + const tags = astModule.getJSDocTags(declaration).filter(astModule.isJSDocTemplateTag); + assert.deepStrictEqual(astModule.getJSDocTypeParameterTags(parameters[0]), [tags[1], tags[2]]); + assert.deepStrictEqual(astModule.getJSDocTypeParameterTags(parameters[1]), [tags[0]]); + assert.deepStrictEqual(astModule.getJSDocTypeParameterTags(parameters[2]), [tags[0]]); + assert.deepStrictEqual(astModule.getJSDocTypeParameterTags(parameters[3]), []); + }); + test("getJSDocParameterTags matches binding patterns by position", () => { using api = spawnAPI(); const source = api.createSourceFile( From 8893c34b13531c08d54a9cbc29c7aca0a08ccaf8 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Wed, 18 Nov 2026 14:17:51 -0800 Subject: [PATCH 3/3] Export isJSDocLinkLike as a type guard Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- packages/typescript/src/ast/is.ts | 5 ++++- packages/typescript/test/sync/ast.test.ts | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/typescript/src/ast/is.ts b/packages/typescript/src/ast/is.ts index 16ba8c4390e11..3efd9cd63ae0e 100644 --- a/packages/typescript/src/ast/is.ts +++ b/packages/typescript/src/ast/is.ts @@ -20,6 +20,9 @@ import type { ForInOrOfStatement, ForStatement, Identifier, + JSDocLink, + JSDocLinkCode, + JSDocLinkPlain, JSDocTypeExpression, JSDocTypeLiteral, JsxTagNameExpression, @@ -309,7 +312,7 @@ function isImportCall(node: Node): node is Node & { readonly expression: MetaPro && (node.expression as MetaProperty).keywordToken === SyntaxKind.ImportKeyword; } -function isJSDocLinkLike(node: Node): boolean { +export function isJSDocLinkLike(node: Node): node is JSDocLink | JSDocLinkCode | JSDocLinkPlain { return isJSDocLink(node) || isJSDocLinkCode(node) || isJSDocLinkPlain(node); } diff --git a/packages/typescript/test/sync/ast.test.ts b/packages/typescript/test/sync/ast.test.ts index 6adaa1f093245..ea9b03dafb519 100644 --- a/packages/typescript/test/sync/ast.test.ts +++ b/packages/typescript/test/sync/ast.test.ts @@ -123,6 +123,21 @@ test("index signatures allow an omitted type", () => { }); describe("JSDoc helpers", { concurrency }, () => { + test("isJSDocLinkLike narrows all three link kinds", () => { + const isLink: (node: Node) => node is astModule.JSDocLink | astModule.JSDocLinkCode | astModule.JSDocLinkPlain = astModule.isJSDocLinkLike; + const nodes: Node[] = [ + factory.createJSDocLink(createIdentifier("target"), "link text"), + factory.createJSDocLinkCode(createIdentifier("target"), "code text"), + factory.createJSDocLinkPlain(createIdentifier("target"), "plain text"), + factory.createJSDocText("ordinary text"), + factory.createJSDocNameReference(createIdentifier("target")), + createIdentifier("target"), + ]; + const links = nodes.filter(isLink); + assert.deepStrictEqual(links, nodes.slice(0, 3)); + assert.deepStrictEqual(links.map(link => link.text), ["link text", "code text", "plain text"]); + }); + test("getJSDocParameterTags matches identifiers by name", () => { using api = spawnAPI(); const source = api.createSourceFile(