exclude nested functions and classes at containingThis check

This commit is contained in:
BigAru
2019-01-23 19:36:00 +01:00
parent dbd58599f4
commit 5ec1201e3a
4 changed files with 45 additions and 3 deletions
@@ -102,7 +102,9 @@ namespace ts.refactor.convertArrowFunctionOrFunctionExpression {
return;
}
forEachChild(child, checkThis);
if (!isClassLike(child) && !isFunctionDeclaration(child) && !isFunctionExpression(child)) {
forEachChild(child, checkThis);
}
});
return containsThis;
@@ -0,0 +1,19 @@
/// <reference path='fourslash.ts' />
//// const zoo = /*x*/f/*w*/unction () {
//// class Animal {
//// weight = 42
//// askWeight() { return this.weight }
//// }
//// const Insect = class {
//// weight = 42
//// askWeight() { return this.weight }
//// }
//// function callTaxi() { this.no = "054 xxx xx xx" }
//// const callPizzaDelivery = function() { this.phone = "064 yyy yy yy"}
//// };
goTo.select("x", "w");
verify.not.refactorAvailable("Convert arrow function or function expression", "Convert to named function");
verify.not.refactorAvailable("Convert arrow function or function expression", "Convert to anonymous function");
verify.refactorAvailable("Convert arrow function or function expression", "Convert to arrow function");
@@ -1,7 +1,9 @@
/// <reference path='fourslash.ts' />
//// const bar = 42;
//// const foo = /*x*/f/*w*/unction() {return this.bar;};
//// const foo = /*x*/f/*w*/unction() {
//// this.bar = "F-Express";
//// return this.bar;
//// };
goTo.select("x", "w");
verify.not.refactorAvailable("Convert arrow function or function expression", "Convert to named function");
@@ -0,0 +1,19 @@
/// <reference path='fourslash.ts' />
//// const zoo = /*x*/(/*w*/) => {
//// class Animal {
//// weight = 42
//// askWeight() { return this.weight }
//// }
//// const Insect = class {
//// weight = 42
//// askWeight() { return this.weight }
//// }
//// function callTaxi() { this.no = "054 xxx xx xx" }
//// const callPizzaDelivery = function() { this.phone = "064 yyy yy yy"}
//// };
goTo.select("x", "w");
verify.refactorAvailable("Convert arrow function or function expression", "Convert to named function");
verify.refactorAvailable("Convert arrow function or function expression", "Convert to anonymous function");
verify.not.refactorAvailable("Convert arrow function or function expression", "Convert to arrow function");