mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fix duplicated JSDoc comments
Incorporate suppressLeadingAndTrailingTrivia just added by @amcasey.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -10,9 +10,6 @@
|
||||
verify.applicableRefactorAvailableAtMarker('1');
|
||||
verify.fileAfterApplyingRefactorAtMarker('1',
|
||||
`class C {
|
||||
/**
|
||||
* @return {...*}
|
||||
*/
|
||||
/**
|
||||
* @return {...*}
|
||||
*/
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
verify.applicableRefactorAvailableAtMarker('1');
|
||||
verify.fileAfterApplyingRefactorAtMarker('1',
|
||||
`class C {
|
||||
/** @type {number | null} */
|
||||
/** @type {number | null} */
|
||||
p: number | null = null;
|
||||
}`, 'Annotate with type from JSDoc', 'annotate');
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
verify.applicableRefactorAvailableAtMarker('1');
|
||||
verify.fileAfterApplyingRefactorAtMarker('1',
|
||||
`declare class C {
|
||||
/** @type {number | null} */
|
||||
/** @type {number | null} */
|
||||
p: number | null;
|
||||
}`, 'Annotate with type from JSDoc', 'annotate');
|
||||
|
||||
Reference in New Issue
Block a user