mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-11 20:37:46 -05:00
fix(48191): Duplicates comments on "Add definite assignment assertion to property" (#48299)
* Suppress leading and trailing comments for adding missing definite assignment assertion action * Suppress leading and trailing comments for adding missing initalizer action * Test for initializer property action
This commit is contained in:
@@ -67,6 +67,7 @@ namespace ts.codefix {
|
||||
}
|
||||
|
||||
function addDefiniteAssignmentAssertion(changeTracker: textChanges.ChangeTracker, propertyDeclarationSourceFile: SourceFile, propertyDeclaration: PropertyDeclaration): void {
|
||||
suppressLeadingAndTrailingTrivia(propertyDeclaration);
|
||||
const property = factory.updatePropertyDeclaration(
|
||||
propertyDeclaration,
|
||||
propertyDeclaration.decorators,
|
||||
@@ -108,6 +109,7 @@ namespace ts.codefix {
|
||||
}
|
||||
|
||||
function addInitializer(changeTracker: textChanges.ChangeTracker, propertyDeclarationSourceFile: SourceFile, propertyDeclaration: PropertyDeclaration, initializer: Expression): void {
|
||||
suppressLeadingAndTrailingTrivia(propertyDeclaration);
|
||||
const property = factory.updatePropertyDeclaration(
|
||||
propertyDeclaration,
|
||||
propertyDeclaration.decorators,
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @strict: true
|
||||
|
||||
//// class T {
|
||||
//// // comment
|
||||
//// a: string;
|
||||
//// }
|
||||
|
||||
verify.codeFix({
|
||||
description: `Add definite assignment assertion to property 'a: string;'`,
|
||||
newFileContent: `class T {
|
||||
// comment
|
||||
a!: string;
|
||||
}`,
|
||||
index: 1
|
||||
})
|
||||
@@ -0,0 +1,15 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @strict: true
|
||||
|
||||
//// class T {
|
||||
//// a: string; // comment
|
||||
//// }
|
||||
|
||||
verify.codeFix({
|
||||
description: `Add definite assignment assertion to property 'a: string;'`,
|
||||
newFileContent: `class T {
|
||||
a!: string; // comment
|
||||
}`,
|
||||
index: 1
|
||||
})
|
||||
@@ -0,0 +1,17 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @strict: true
|
||||
|
||||
//// class T {
|
||||
//// // comment
|
||||
//// a: 2;
|
||||
//// }
|
||||
|
||||
verify.codeFix({
|
||||
description: `Add initializer to property 'a'`,
|
||||
newFileContent: `class T {
|
||||
// comment
|
||||
a: 2 = 2;
|
||||
}`,
|
||||
index: 2
|
||||
})
|
||||
@@ -0,0 +1,15 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @strict: true
|
||||
|
||||
//// class T {
|
||||
//// a: 2; // comment
|
||||
//// }
|
||||
|
||||
verify.codeFix({
|
||||
description: `Add initializer to property 'a'`,
|
||||
newFileContent: `class T {
|
||||
a: 2 = 2; // comment
|
||||
}`,
|
||||
index: 2
|
||||
})
|
||||
Reference in New Issue
Block a user