Skip to content

Commit 4cf289e

Browse files
committed
Fix whitespace around inserted property initializer
Fixes microsoft#18741
1 parent 686fd1e commit 4cf289e

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

src/services/codefixes/fixAddMissingMember.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ namespace ts.codefix {
112112
createIdentifier("undefined")));
113113

114114
const propertyInitializationChangeTracker = textChanges.ChangeTracker.fromContext(context);
115-
propertyInitializationChangeTracker.insertNodeAt(
115+
propertyInitializationChangeTracker.insertNodeBefore(
116116
classDeclarationSourceFile,
117-
classConstructor.body.getEnd() - 1,
117+
classConstructor.body.getLastToken(),
118118
propertyInitialization,
119-
{ prefix: context.newLineCharacter, suffix: context.newLineCharacter });
119+
{ suffix: context.newLineCharacter });
120120

121121
const initializeAction = {
122122
description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Initialize_property_0_in_the_constructor), [tokenName]),

tests/cases/fourslash/codeFixAddMissingMember4.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
verify.codeFix({
1616
description: "Initialize property 'foo' in the constructor.",
1717
index: 0,
18-
// TODO: GH#18741 and GH#18445
18+
// TODO: GH#18445
1919
newFileContent: `class C {
2020
constructor() {
21-
\r
22-
this.foo = undefined;\r
23-
}
21+
this.foo = undefined;\r
22+
}
2423
method() {
2524
this.foo === 10;
2625
}

tests/cases/fourslash/codeFixAddMissingMember6.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
verify.codeFix({
1414
description: "Initialize property 'foo' in the constructor.",
1515
index: 0,
16-
// TODO: GH#18741 and GH#18445
16+
// TODO: GH#18445
1717
newFileContent: `class C {
1818
constructor() {
19-
\r
20-
this.foo = undefined;\r
21-
}
19+
this.foo = undefined;\r
20+
}
2221
prop = ()=>{ this.foo === 10 };
2322
}`
2423
});

0 commit comments

Comments
 (0)