mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
fix(50888): Organize Imports may delete preceding comments when all members of all import statements are unused (#50983)
* fix(50888): preserve preceding comments of the deleted import * update tests
This commit is contained in:
parent
6327931d4f
commit
8f2ee38b52
@ -145,6 +145,7 @@ export function organizeImports(
|
||||
// Consider the first node to have trailingTrivia as we want to exclude the
|
||||
// "header" comment.
|
||||
changeTracker.deleteNodes(sourceFile, oldImportDecls, {
|
||||
leadingTriviaOption: textChanges.LeadingTriviaOption.Exclude,
|
||||
trailingTriviaOption: textChanges.TrailingTriviaOption.Include,
|
||||
}, /*hasTrailingComment*/ true);
|
||||
}
|
||||
|
||||
33
tests/cases/fourslash/organizeImports14.ts
Normal file
33
tests/cases/fourslash/organizeImports14.ts
Normal file
@ -0,0 +1,33 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @filename: /a.ts
|
||||
////export const foo = 1;
|
||||
|
||||
// @filename: /b.ts
|
||||
/////**
|
||||
//// * Module doc comment
|
||||
//// *
|
||||
//// * @module
|
||||
//// */
|
||||
////
|
||||
////// comment 1
|
||||
////
|
||||
////// comment 2
|
||||
////
|
||||
////import { foo } from "./a";
|
||||
////import { foo } from "./a";
|
||||
////import { foo } from "./a";
|
||||
|
||||
goTo.file("/b.ts");
|
||||
verify.organizeImports(
|
||||
`/**
|
||||
* Module doc comment
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
|
||||
// comment 1
|
||||
|
||||
// comment 2
|
||||
|
||||
`);
|
||||
31
tests/cases/fourslash/organizeImports15.ts
Normal file
31
tests/cases/fourslash/organizeImports15.ts
Normal file
@ -0,0 +1,31 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @filename: /a.ts
|
||||
////export const foo = 1;
|
||||
|
||||
// @filename: /b.ts
|
||||
/////**
|
||||
//// * Module doc comment
|
||||
//// *
|
||||
//// * @module
|
||||
//// */
|
||||
////
|
||||
////// comment 1
|
||||
////
|
||||
////// comment 2
|
||||
////
|
||||
////import { foo } from "./a";
|
||||
|
||||
goTo.file("/b.ts");
|
||||
verify.organizeImports(
|
||||
`/**
|
||||
* Module doc comment
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
|
||||
// comment 1
|
||||
|
||||
// comment 2
|
||||
|
||||
`);
|
||||
Loading…
x
Reference in New Issue
Block a user