Merge pull request #13759 from Microsoft/fixMissingThis

Quick fix to add missing 'this.' for property accesses
This commit is contained in:
Daniel Rosenwasser 2017-01-30 13:03:24 -08:00 committed by GitHub
commit d38bc54002
6 changed files with 41 additions and 1 deletions

View file

@ -3267,6 +3267,10 @@
"category": "Message",
"code": 90007
},
"Add 'this.' to unresolved variable.": {
"category": "Message",
"code": 90008
},
"Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig": {
"category": "Error",
"code": 90009

View file

@ -0,0 +1,16 @@
/* @internal */
namespace ts.codefix {
registerCodeFix({
errorCodes: [Diagnostics.Cannot_find_name_0_Did_you_mean_the_instance_member_this_0.code],
getCodeActions: (context: CodeFixContext) => {
const sourceFile = context.sourceFile;
const token = getTokenAtPosition(sourceFile, context.span.start);
const start = token.getStart(sourceFile);
return [{
description: getLocaleSpecificMessage(Diagnostics.Add_this_to_unresolved_variable),
changes: [{ fileName: sourceFile.fileName, textChanges: [{ newText: "this.", span: { start, length: 0 } }] }]
}];
}
});
}

View file

@ -3,7 +3,7 @@
/// <reference path="fixClassSuperMustPrecedeThisAccess.ts" />
/// <reference path="fixConstructorForDerivedNeedSuperCall.ts" />
/// <reference path="fixExtendsInterfaceBecomesImplements.ts" />
/// <reference path="fixForgottenThisPropertyAccess.ts" />
/// <reference path='unusedIdentifierFixes.ts' />
/// <reference path='importFixes.ts' />
/// <reference path='helpers.ts' />

View file

@ -83,6 +83,7 @@
"codefixes/fixClassDoesntImplementInheritedAbstractMember.ts",
"codefixes/fixClassSuperMustPrecedeThisAccess.ts",
"codefixes/fixConstructorForDerivedNeedSuperCall.ts",
"codefixes/fixForgottenThisPropertyAccess.ts",
"codefixes/fixes.ts",
"codefixes/helpers.ts",
"codefixes/importFixes.ts",

View file

@ -0,0 +1,10 @@
/// <reference path='fourslash.ts' />
////class C {
//// foo: number;
//// constructor() {
//// [|foo = 10|];
//// }
////}
verify.rangeAfterCodeFix("this.foo = 10");

View file

@ -0,0 +1,9 @@
/// <reference path='fourslash.ts' />
////class C {
//// constructor(public foo) {
//// }
//// bar() { [|foo = 10|] };
////}
verify.rangeAfterCodeFix("this.foo = 10");