Fix whitespace around inserted property initializer

Fixes #18741
This commit is contained in:
Andrew Casey 2017-10-04 11:26:41 -07:00
parent 686fd1e62d
commit 4cf289e1a5
3 changed files with 9 additions and 11 deletions

View file

@ -112,11 +112,11 @@ namespace ts.codefix {
createIdentifier("undefined")));
const propertyInitializationChangeTracker = textChanges.ChangeTracker.fromContext(context);
propertyInitializationChangeTracker.insertNodeAt(
propertyInitializationChangeTracker.insertNodeBefore(
classDeclarationSourceFile,
classConstructor.body.getEnd() - 1,
classConstructor.body.getLastToken(),
propertyInitialization,
{ prefix: context.newLineCharacter, suffix: context.newLineCharacter });
{ suffix: context.newLineCharacter });
const initializeAction = {
description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Initialize_property_0_in_the_constructor), [tokenName]),

View file

@ -15,12 +15,11 @@
verify.codeFix({
description: "Initialize property 'foo' in the constructor.",
index: 0,
// TODO: GH#18741 and GH#18445
// TODO: GH#18445
newFileContent: `class C {
constructor() {
\r
this.foo = undefined;\r
}
this.foo = undefined;\r
}
method() {
this.foo === 10;
}

View file

@ -13,12 +13,11 @@
verify.codeFix({
description: "Initialize property 'foo' in the constructor.",
index: 0,
// TODO: GH#18741 and GH#18445
// TODO: GH#18445
newFileContent: `class C {
constructor() {
\r
this.foo = undefined;\r
}
this.foo = undefined;\r
}
prop = ()=>{ this.foo === 10 };
}`
});