Fix duplicated JSDoc comments

Incorporate suppressLeadingAndTrailingTrivia just added by @amcasey.
This commit is contained in:
Nathan Shively-Sanders
2017-10-12 14:28:34 -07:00
parent c2c18a8d06
commit f35764d4ec
4 changed files with 7 additions and 8 deletions

View File

@@ -62,14 +62,16 @@ namespace ts.refactor.annotateWithTypeFromJSDoc {
const sourceFile = context.file;
const token = getTokenAtPosition(sourceFile, context.startPosition, /*includeJsDocComment*/ false);
const decl = findAncestor(token, isDeclarationWithType);
const jsdocType = getJSDocReturnType(decl) || getJSDocType(decl);
const jsdocType = getJSDocType(decl);
if (!decl || !jsdocType || decl.type) {
Debug.fail(`!decl || !jsdocType || decl.type: !${decl} || !${jsdocType} || ${decl.type}`);
return undefined;
}
const changeTracker = textChanges.ChangeTracker.fromContext(context);
changeTracker.replaceRange(sourceFile, { pos: decl.getStart(), end: decl.end }, addType(decl, transformJSDocType(jsdocType) as TypeNode));
const declarationWithType = addType(decl, transformJSDocType(jsdocType) as TypeNode);
suppressLeadingAndTrailingTrivia(declarationWithType);
changeTracker.replaceRange(sourceFile, { pos: decl.getStart(), end: decl.end }, declarationWithType);
return {
edits: changeTracker.getChanges(),
renameFilename: undefined,
@@ -87,7 +89,9 @@ namespace ts.refactor.annotateWithTypeFromJSDoc {
const token = getTokenAtPosition(sourceFile, context.startPosition, /*includeJsDocComment*/ false);
const decl = findAncestor(token, isFunctionLikeDeclaration);
const changeTracker = textChanges.ChangeTracker.fromContext(context);
changeTracker.replaceRange(sourceFile, { pos: decl.getStart(), end: decl.end }, addTypesToFunctionLike(decl));
const functionWithType = addTypesToFunctionLike(decl);
suppressLeadingAndTrailingTrivia(functionWithType);
changeTracker.replaceRange(sourceFile, { pos: decl.getStart(), end: decl.end }, functionWithType);
return {
edits: changeTracker.getChanges(),
renameFilename: undefined,