@@ -243,7 +243,7 @@ namespace ts.JsDoc {
243
243
}
244
244
245
245
const tokenAtPos = getTokenAtPosition ( sourceFile , position , /*includeJsDocComment*/ false ) ;
246
- const tokenStart = tokenAtPos . getStart ( ) ;
246
+ const tokenStart = tokenAtPos . getStart ( sourceFile ) ;
247
247
if ( ! tokenAtPos || tokenStart < position ) {
248
248
return undefined ;
249
249
}
@@ -253,7 +253,7 @@ namespace ts.JsDoc {
253
253
return undefined ;
254
254
}
255
255
const { commentOwner, parameters } = commentOwnerInfo ;
256
- if ( commentOwner . getStart ( ) < position ) {
256
+ if ( commentOwner . getStart ( sourceFile ) < position ) {
257
257
return undefined ;
258
258
}
259
259
@@ -268,19 +268,6 @@ namespace ts.JsDoc {
268
268
269
269
// replace non-whitespace characters in prefix with spaces.
270
270
const indentationStr = sourceFile . text . substr ( lineStart , posLineAndChar . character ) . replace ( / \S / i, ( ) => " " ) ;
271
- const isJavaScriptFile = hasJavaScriptFileExtension ( sourceFile . fileName ) ;
272
-
273
- let docParams = "" ;
274
- for ( let i = 0 ; i < parameters . length ; i ++ ) {
275
- const currentName = parameters [ i ] . name ;
276
- const paramName = currentName . kind === SyntaxKind . Identifier ? currentName . escapedText : "param" + i ;
277
- if ( isJavaScriptFile ) {
278
- docParams += `${ indentationStr } * @param {any} ${ paramName } ${ newLine } ` ;
279
- }
280
- else {
281
- docParams += `${ indentationStr } * @param ${ paramName } ${ newLine } ` ;
282
- }
283
- }
284
271
285
272
// A doc comment consists of the following
286
273
// * The opening comment line
@@ -293,13 +280,21 @@ namespace ts.JsDoc {
293
280
indentationStr + " * " ;
294
281
const result =
295
282
preamble + newLine +
296
- docParams +
283
+ parameterDocComments ( parameters , hasJavaScriptFileExtension ( sourceFile . fileName ) , indentationStr , newLine ) +
297
284
indentationStr + " */" +
298
285
( tokenStart === position ? newLine + indentationStr : "" ) ;
299
286
300
287
return { newText : result , caretOffset : preamble . length } ;
301
288
}
302
289
290
+ function parameterDocComments ( parameters : ReadonlyArray < ParameterDeclaration > , isJavaScriptFile : boolean , indentationStr : string , newLine : string ) : string {
291
+ return parameters . map ( ( { name, dotDotDotToken } , i ) => {
292
+ const paramName = name . kind === SyntaxKind . Identifier ? name . text : "param" + i ;
293
+ const type = isJavaScriptFile ? ( dotDotDotToken ? "{...any} " : "{any} " ) : "" ;
294
+ return `${ indentationStr } * @param ${ type } ${ paramName } ${ newLine } ` ;
295
+ } ) . join ( "" ) ;
296
+ }
297
+
303
298
interface CommentOwnerInfo {
304
299
readonly commentOwner : Node ;
305
300
readonly parameters ?: ReadonlyArray < ParameterDeclaration > ;
0 commit comments