@@ -122,6 +122,88 @@ test("index signatures allow an omitted type", () => {
122122 assert . strictEqual ( declaration . members . length , 2 ) ;
123123} ) ;
124124
125+ describe ( "JSDoc helpers" , { concurrency } , ( ) => {
126+ test ( "isJSDocLinkLike narrows all three link kinds" , ( ) => {
127+ const isLink : ( node : Node ) => node is astModule . JSDocLink | astModule . JSDocLinkCode | astModule . JSDocLinkPlain = astModule . isJSDocLinkLike ;
128+ const nodes : Node [ ] = [
129+ factory . createJSDocLink ( createIdentifier ( "target" ) , "link text" ) ,
130+ factory . createJSDocLinkCode ( createIdentifier ( "target" ) , "code text" ) ,
131+ factory . createJSDocLinkPlain ( createIdentifier ( "target" ) , "plain text" ) ,
132+ factory . createJSDocText ( "ordinary text" ) ,
133+ factory . createJSDocNameReference ( createIdentifier ( "target" ) ) ,
134+ createIdentifier ( "target" ) ,
135+ ] ;
136+ const links = nodes . filter ( isLink ) ;
137+ assert . deepStrictEqual ( links , nodes . slice ( 0 , 3 ) ) ;
138+ assert . deepStrictEqual ( links . map ( link => link . text ) , [ "link text" , "code text" , "plain text" ] ) ;
139+ } ) ;
140+
141+ test ( "getJSDocParameterTags matches identifiers by name" , ( ) => {
142+ using api = spawnAPI ( ) ;
143+ const source = api . createSourceFile (
144+ "/parameters.ts" ,
145+ `/**
146+ * @param second the second parameter
147+ * @param first the first parameter
148+ * @param first another description
149+ * @param first.property a nested property
150+ */
151+ function f(first: object, second: string, undocumented: number) {}
152+ ` ,
153+ ) . sourceFile ;
154+ const declaration = source . statements [ 0 ] ;
155+ assert . ok ( astModule . isFunctionDeclaration ( declaration ) ) ;
156+ const tags = astModule . getJSDocTags ( declaration ) . filter ( astModule . isJSDocParameterTag ) ;
157+ assert . deepStrictEqual ( astModule . getJSDocParameterTags ( declaration . parameters [ 0 ] ) , [ tags [ 1 ] , tags [ 2 ] ] ) ;
158+ assert . deepStrictEqual ( astModule . getJSDocParameterTags ( declaration . parameters [ 1 ] ) , [ tags [ 0 ] ] ) ;
159+ assert . deepStrictEqual ( astModule . getJSDocParameterTags ( declaration . parameters [ 2 ] ) , [ ] ) ;
160+ } ) ;
161+
162+ test ( "getJSDocTypeParameterTags matches names within template tags" , ( ) => {
163+ using api = spawnAPI ( ) ;
164+ const source = api . createSourceFile (
165+ "/templates.ts" ,
166+ `/**
167+ * @template U, V shared description
168+ * @template T the first description
169+ * @template T another description
170+ * @template Other an unrelated type parameter
171+ */
172+ function f<T, U, V, Undocumented>() {}
173+ ` ,
174+ ) . sourceFile ;
175+ const declaration = source . statements [ 0 ] ;
176+ assert . ok ( astModule . isFunctionDeclaration ( declaration ) ) ;
177+ const parameters = declaration . typeParameters ;
178+ assert . ok ( parameters ) ;
179+ const tags = astModule . getJSDocTags ( declaration ) . filter ( astModule . isJSDocTemplateTag ) ;
180+ assert . deepStrictEqual ( astModule . getJSDocTypeParameterTags ( parameters [ 0 ] ) , [ tags [ 1 ] , tags [ 2 ] ] ) ;
181+ assert . deepStrictEqual ( astModule . getJSDocTypeParameterTags ( parameters [ 1 ] ) , [ tags [ 0 ] ] ) ;
182+ assert . deepStrictEqual ( astModule . getJSDocTypeParameterTags ( parameters [ 2 ] ) , [ tags [ 0 ] ] ) ;
183+ assert . deepStrictEqual ( astModule . getJSDocTypeParameterTags ( parameters [ 3 ] ) , [ ] ) ;
184+ } ) ;
185+
186+ test ( "getJSDocParameterTags matches binding patterns by position" , ( ) => {
187+ using api = spawnAPI ( ) ;
188+ const source = api . createSourceFile (
189+ "/bindings.js" ,
190+ `/**
191+ * @param {string} named a named parameter
192+ * @param {object} options an object parameter
193+ * @param {Array} entries an array parameter
194+ */
195+ function f(named, { value }, [entry], { undocumented }) {}
196+ ` ,
197+ ) . sourceFile ;
198+ const declaration = source . statements [ 0 ] ;
199+ assert . ok ( astModule . isFunctionDeclaration ( declaration ) ) ;
200+ const tags = astModule . getJSDocTags ( declaration ) . filter ( astModule . isJSDocParameterTag ) ;
201+ assert . deepStrictEqual ( astModule . getJSDocParameterTags ( declaration . parameters [ 1 ] ) , [ tags [ 1 ] ] ) ;
202+ assert . deepStrictEqual ( astModule . getJSDocParameterTags ( declaration . parameters [ 2 ] ) , [ tags [ 2 ] ] ) ;
203+ assert . deepStrictEqual ( astModule . getJSDocParameterTags ( declaration . parameters [ 3 ] ) , [ ] ) ;
204+ } ) ;
205+ } ) ;
206+
125207describe ( "AST property contracts" , { concurrency } , ( ) => {
126208 test ( "JSDoc typedefs expose type nodes" , ( ) => {
127209 using api = spawnAPI ( ) ;
0 commit comments