@@ -129,7 +129,7 @@ namespace ts.codefix {
129
129
if ( typeNode ) {
130
130
// Note that the codefix will never fire with an existing `@type` tag, so there is no need to merge tags
131
131
const typeTag = factory . createJSDocTypeTag ( /*tagName*/ undefined , factory . createJSDocTypeExpression ( typeNode ) , /*comment*/ undefined ) ;
132
- addJSDocTags ( changes , sourceFile , cast ( parent . parent . parent , isExpressionStatement ) , [ typeTag ] ) ;
132
+ changes . addJSDocTags ( sourceFile , cast ( parent . parent . parent , isExpressionStatement ) , [ typeTag ] ) ;
133
133
}
134
134
importAdder . writeFixes ( changes ) ;
135
135
return parent ;
@@ -269,7 +269,7 @@ namespace ts.codefix {
269
269
}
270
270
271
271
function annotateJSDocThis ( changes : textChanges . ChangeTracker , sourceFile : SourceFile , containingFunction : SignatureDeclaration , typeNode : TypeNode ) {
272
- addJSDocTags ( changes , sourceFile , containingFunction , [
272
+ changes . addJSDocTags ( sourceFile , containingFunction , [
273
273
factory . createJSDocThisTag ( /*tagName*/ undefined , factory . createJSDocTypeExpression ( typeNode ) ) ,
274
274
] ) ;
275
275
}
@@ -309,7 +309,7 @@ namespace ts.codefix {
309
309
}
310
310
const typeExpression = factory . createJSDocTypeExpression ( typeNode ) ;
311
311
const typeTag = isGetAccessorDeclaration ( declaration ) ? factory . createJSDocReturnTag ( /*tagName*/ undefined , typeExpression , /*comment*/ undefined ) : factory . createJSDocTypeTag ( /*tagName*/ undefined , typeExpression , /*comment*/ undefined ) ;
312
- addJSDocTags ( changes , sourceFile , parent , [ typeTag ] ) ;
312
+ changes . addJSDocTags ( sourceFile , parent , [ typeTag ] ) ;
313
313
}
314
314
else if ( ! tryReplaceImportTypeNodeWithAutoImport ( typeNode , declaration , sourceFile , changes , importAdder , getEmitScriptTarget ( program . getCompilerOptions ( ) ) ) ) {
315
315
changes . tryInsertTypeAnnotation ( sourceFile , declaration , typeNode ) ;
@@ -376,46 +376,7 @@ namespace ts.codefix {
376
376
else {
377
377
const paramTags = map ( inferences , ( { name, typeNode, isOptional } ) =>
378
378
factory . createJSDocParameterTag ( /*tagName*/ undefined , name , /*isBracketed*/ ! ! isOptional , factory . createJSDocTypeExpression ( typeNode ) , /* isNameFirst */ false , /*comment*/ undefined ) ) ;
379
- addJSDocTags ( changes , sourceFile , signature , paramTags ) ;
380
- }
381
- }
382
-
383
- export function addJSDocTags ( changes : textChanges . ChangeTracker , sourceFile : SourceFile , parent : HasJSDoc , newTags : readonly JSDocTag [ ] ) : void {
384
- const comments = flatMap ( parent . jsDoc , j => typeof j . comment === "string" ? factory . createJSDocText ( j . comment ) : j . comment ) as JSDocComment [ ] ;
385
- const oldTags = flatMapToMutable ( parent . jsDoc , j => j . tags ) ;
386
- const unmergedNewTags = newTags . filter ( newTag => ! oldTags || ! oldTags . some ( ( tag , i ) => {
387
- const merged = tryMergeJsdocTags ( tag , newTag ) ;
388
- if ( merged ) oldTags [ i ] = merged ;
389
- return ! ! merged ;
390
- } ) ) ;
391
- const tag = factory . createJSDocComment ( factory . createNodeArray ( intersperse ( comments , factory . createJSDocText ( "\n" ) ) ) , factory . createNodeArray ( [ ...( oldTags || emptyArray ) , ...unmergedNewTags ] ) ) ;
392
- const jsDocNode = parent . kind === SyntaxKind . ArrowFunction ? getJsDocNodeForArrowFunction ( parent ) : parent ;
393
- jsDocNode . jsDoc = parent . jsDoc ;
394
- jsDocNode . jsDocCache = parent . jsDocCache ;
395
- changes . insertJsdocCommentBefore ( sourceFile , jsDocNode , tag ) ;
396
- }
397
-
398
- function getJsDocNodeForArrowFunction ( signature : ArrowFunction ) : HasJSDoc {
399
- if ( signature . parent . kind === SyntaxKind . PropertyDeclaration ) {
400
- return signature . parent as HasJSDoc ;
401
- }
402
- return signature . parent . parent as HasJSDoc ;
403
- }
404
-
405
- function tryMergeJsdocTags ( oldTag : JSDocTag , newTag : JSDocTag ) : JSDocTag | undefined {
406
- if ( oldTag . kind !== newTag . kind ) {
407
- return undefined ;
408
- }
409
- switch ( oldTag . kind ) {
410
- case SyntaxKind . JSDocParameterTag : {
411
- const oldParam = oldTag as JSDocParameterTag ;
412
- const newParam = newTag as JSDocParameterTag ;
413
- return isIdentifier ( oldParam . name ) && isIdentifier ( newParam . name ) && oldParam . name . escapedText === newParam . name . escapedText
414
- ? factory . createJSDocParameterTag ( /*tagName*/ undefined , newParam . name , /*isBracketed*/ false , newParam . typeExpression , newParam . isNameFirst , oldParam . comment )
415
- : undefined ;
416
- }
417
- case SyntaxKind . JSDocReturnTag :
418
- return factory . createJSDocReturnTag ( /*tagName*/ undefined , ( newTag as JSDocReturnTag ) . typeExpression , oldTag . comment ) ;
379
+ changes . addJSDocTags ( sourceFile , signature , paramTags ) ;
419
380
}
420
381
}
421
382
0 commit comments