Handle trivia in code fix forgotten-this

Fixes #21433
This commit is contained in:
Andrew Casey 2018-01-30 13:25:39 -08:00
parent b0ea899d13
commit 3020f3d2e6
2 changed files with 18 additions and 1 deletions

View file

@ -21,6 +21,8 @@ namespace ts.codefix {
}
function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, token: Identifier): void {
changes.replaceNode(sourceFile, token, createPropertyAccess(createThis(), token));
// TODO (https://github.com/Microsoft/TypeScript/issues/21246): use shared helper
suppressLeadingAndTrailingTrivia(token);
changes.replaceRange(sourceFile, { pos: token.getStart(), end: token.end }, createPropertyAccess(createThis(), token));
}
}

View file

@ -0,0 +1,15 @@
/// <reference path='fourslash.ts' />
////class C {
//// foo: number;
//// constructor() {[|
//// /* a comment */foo = 10;
//// |]}
////}
verify.codeFix({
description: "Add 'this.' to unresolved variable",
newRangeContent: `
/* a comment */this.foo = 10;
`
});