mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-23 07:07:09 -05:00
Don't delete comments when deleting unused declarations (#37467)
* don't delete comment on variable declaration * add more declaration kinds * don't copy comment in convertes6 class * don't copy comments in convertToES6Class * add tests * use isAnyImportSyntax * handle mixed comment types * update tests
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
verify.codeFix({
|
||||
description: "Convert function to an ES2015 class",
|
||||
newFileContent:
|
||||
`// Comment\r
|
||||
`// Comment
|
||||
class fn {\r
|
||||
constructor() {\r
|
||||
this.baz = 10;\r
|
||||
@@ -0,0 +1,31 @@
|
||||
// @allowNonTsExtensions: true
|
||||
// @Filename: test123.js
|
||||
|
||||
/// <reference path="../fourslash.ts" />
|
||||
|
||||
//// /**
|
||||
//// * JSDoc Comment
|
||||
//// */
|
||||
//// function fn() {
|
||||
//// this.baz = 10;
|
||||
//// }
|
||||
//// /*1*/fn.prototype.bar = function () {
|
||||
//// console.log('hello world');
|
||||
//// }
|
||||
|
||||
verify.codeFix({
|
||||
description: "Convert function to an ES2015 class",
|
||||
newFileContent:
|
||||
`/**\r
|
||||
* JSDoc Comment\r
|
||||
*/\r
|
||||
class fn {\r
|
||||
constructor() {\r
|
||||
this.baz = 10;\r
|
||||
}\r
|
||||
bar() {\r
|
||||
console.log('hello world');\r
|
||||
}\r
|
||||
}\r
|
||||
`,
|
||||
});
|
||||
@@ -8,4 +8,5 @@
|
||||
//// } |]
|
||||
|
||||
verify.rangeAfterCodeFix(`namespace greeter {
|
||||
/* comment1 */
|
||||
}`);
|
||||
16
tests/cases/fourslash/unusedClassInNamespaceWithTrivia2.ts
Normal file
16
tests/cases/fourslash/unusedClassInNamespaceWithTrivia2.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// [| namespace greeter {
|
||||
//// // Do not remove
|
||||
//// /**
|
||||
//// * JSDoc Comment
|
||||
//// */
|
||||
//// class /* comment2 */ class1 {
|
||||
//// }
|
||||
//// } |]
|
||||
|
||||
verify.rangeAfterCodeFix(`namespace greeter {
|
||||
// Do not remove
|
||||
}`);
|
||||
|
||||
@@ -8,4 +8,5 @@
|
||||
//// } |]
|
||||
|
||||
verify.rangeAfterCodeFix(`namespace greeter {
|
||||
// some legit comments
|
||||
}`);
|
||||
|
||||
16
tests/cases/fourslash/unusedFunctionInNamespaceWithTrivia.ts
Normal file
16
tests/cases/fourslash/unusedFunctionInNamespaceWithTrivia.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
//// [| namespace greeter {
|
||||
//// // Do not remove
|
||||
//// /**
|
||||
//// * JSDoc Comment
|
||||
//// */
|
||||
//// function function1() {
|
||||
//// }/*1*/
|
||||
//// } |]
|
||||
|
||||
verify.rangeAfterCodeFix(`namespace greeter {
|
||||
// Do not remove
|
||||
}`);
|
||||
|
||||
20
tests/cases/fourslash/unusedVariableWithTrivia1.ts
Normal file
20
tests/cases/fourslash/unusedVariableWithTrivia1.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////[|namespace greeter {
|
||||
//// // do not remove comment
|
||||
//// let a = 0;
|
||||
//// // comment
|
||||
//// let b = 0;
|
||||
//// b;
|
||||
////}|]
|
||||
|
||||
verify.codeFix({
|
||||
description: "Remove unused declaration for: 'a'",
|
||||
newRangeContent: `namespace greeter {
|
||||
// do not remove comment
|
||||
// comment
|
||||
let b = 0;
|
||||
b;
|
||||
}`
|
||||
});
|
||||
17
tests/cases/fourslash/unusedVariableWithTrivia2.ts
Normal file
17
tests/cases/fourslash/unusedVariableWithTrivia2.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @noUnusedLocals: true
|
||||
////[|namespace greeter {
|
||||
//// // Do not remove
|
||||
//// /**
|
||||
//// * JSDoc Comment
|
||||
//// */
|
||||
//// let a = 0;
|
||||
////}|]
|
||||
|
||||
verify.codeFix({
|
||||
description: "Remove unused declaration for: 'a'",
|
||||
newRangeContent: `namespace greeter {
|
||||
// Do not remove
|
||||
}`
|
||||
});
|
||||
Reference in New Issue
Block a user