Skip to content

Commit 5ec1201

Browse files
committed
exclude nested functions and classes at containingThis check
1 parent dbd5859 commit 5ec1201

4 files changed

+45
-3
lines changed

src/services/refactors/convertArrowFunctionOrFunctionExpression.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ namespace ts.refactor.convertArrowFunctionOrFunctionExpression {
102102
return;
103103
}
104104

105-
forEachChild(child, checkThis);
105+
if (!isClassLike(child) && !isFunctionDeclaration(child) && !isFunctionExpression(child)) {
106+
forEachChild(child, checkThis);
107+
}
106108
});
107109

108110
return containsThis;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//// const zoo = /*x*/f/*w*/unction () {
4+
//// class Animal {
5+
//// weight = 42
6+
//// askWeight() { return this.weight }
7+
//// }
8+
//// const Insect = class {
9+
//// weight = 42
10+
//// askWeight() { return this.weight }
11+
//// }
12+
//// function callTaxi() { this.no = "054 xxx xx xx" }
13+
//// const callPizzaDelivery = function() { this.phone = "064 yyy yy yy"}
14+
//// };
15+
16+
goTo.select("x", "w");
17+
verify.not.refactorAvailable("Convert arrow function or function expression", "Convert to named function");
18+
verify.not.refactorAvailable("Convert arrow function or function expression", "Convert to anonymous function");
19+
verify.refactorAvailable("Convert arrow function or function expression", "Convert to arrow function");

tests/cases/fourslash/refactorConvertArrowFunctionOrFunctionExpression_Availability_Anon_this.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/// <reference path='fourslash.ts' />
22

3-
//// const bar = 42;
4-
//// const foo = /*x*/f/*w*/unction() {return this.bar;};
3+
//// const foo = /*x*/f/*w*/unction() {
4+
//// this.bar = "F-Express";
5+
//// return this.bar;
6+
//// };
57

68
goTo.select("x", "w");
79
verify.not.refactorAvailable("Convert arrow function or function expression", "Convert to named function");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//// const zoo = /*x*/(/*w*/) => {
4+
//// class Animal {
5+
//// weight = 42
6+
//// askWeight() { return this.weight }
7+
//// }
8+
//// const Insect = class {
9+
//// weight = 42
10+
//// askWeight() { return this.weight }
11+
//// }
12+
//// function callTaxi() { this.no = "054 xxx xx xx" }
13+
//// const callPizzaDelivery = function() { this.phone = "064 yyy yy yy"}
14+
//// };
15+
16+
goTo.select("x", "w");
17+
verify.refactorAvailable("Convert arrow function or function expression", "Convert to named function");
18+
verify.refactorAvailable("Convert arrow function or function expression", "Convert to anonymous function");
19+
verify.not.refactorAvailable("Convert arrow function or function expression", "Convert to arrow function");

0 commit comments

Comments
 (0)