@@ -243,7 +243,7 @@ namespace ts.JsDoc {
243243 }
244244
245245 const tokenAtPos = getTokenAtPosition ( sourceFile , position , /*includeJsDocComment*/ false ) ;
246- const tokenStart = tokenAtPos . getStart ( ) ;
246+ const tokenStart = tokenAtPos . getStart ( sourceFile ) ;
247247 if ( ! tokenAtPos || tokenStart < position ) {
248248 return undefined ;
249249 }
@@ -253,7 +253,7 @@ namespace ts.JsDoc {
253253 return undefined ;
254254 }
255255 const { commentOwner, parameters } = commentOwnerInfo ;
256- if ( commentOwner . getStart ( ) < position ) {
256+ if ( commentOwner . getStart ( sourceFile ) < position ) {
257257 return undefined ;
258258 }
259259
@@ -268,19 +268,6 @@ namespace ts.JsDoc {
268268
269269 // replace non-whitespace characters in prefix with spaces.
270270 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- }
284271
285272 // A doc comment consists of the following
286273 // * The opening comment line
@@ -293,13 +280,21 @@ namespace ts.JsDoc {
293280 indentationStr + " * " ;
294281 const result =
295282 preamble + newLine +
296- docParams +
283+ parameterDocComments ( parameters , hasJavaScriptFileExtension ( sourceFile . fileName ) , indentationStr , newLine ) +
297284 indentationStr + " */" +
298285 ( tokenStart === position ? newLine + indentationStr : "" ) ;
299286
300287 return { newText : result , caretOffset : preamble . length } ;
301288 }
302289
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+
303298 interface CommentOwnerInfo {
304299 readonly commentOwner : Node ;
305300 readonly parameters ?: ReadonlyArray < ParameterDeclaration > ;
0 commit comments