File tree 3 files changed +58
-1
lines changed
3 files changed +58
-1
lines changed Original file line number Diff line number Diff line change @@ -405,6 +405,20 @@ namespace ts.refactor.extractSymbol {
405
405
rangeFacts |= RangeFacts . UsesThis ;
406
406
}
407
407
break ;
408
+ case SyntaxKind . ArrowFunction :
409
+ // check if arrow function uses this
410
+ forEachChild ( node , function check ( n ) {
411
+ if ( isThis ( n ) ) {
412
+ rangeFacts |= RangeFacts . UsesThis ;
413
+ }
414
+ else if ( isClassLike ( n ) || ( isFunctionLike ( n ) && ! isArrowFunction ( n ) ) ) {
415
+ return false ;
416
+ }
417
+ else {
418
+ forEachChild ( n , check ) ;
419
+ }
420
+ } ) ;
421
+ // falls through
408
422
case SyntaxKind . ClassDeclaration :
409
423
case SyntaxKind . FunctionDeclaration :
410
424
if ( isSourceFile ( node . parent ) && node . parent . externalModuleIndicator === undefined ) {
@@ -418,7 +432,7 @@ namespace ts.refactor.extractSymbol {
418
432
case SyntaxKind . Constructor :
419
433
case SyntaxKind . GetAccessor :
420
434
case SyntaxKind . SetAccessor :
421
- // do not dive into functions (except arrow functions) or classes
435
+ // do not dive into functions or classes
422
436
return false ;
423
437
}
424
438
Original file line number Diff line number Diff line change
1
+ /// <reference path='fourslash.ts' />
2
+
3
+ ////const foo = /*start*/{
4
+ //// a: 1,
5
+ //// b: () => { return 1; }
6
+ //// }/*end*/
7
+
8
+ goTo . select ( "start" , "end" ) ;
9
+ edit . applyRefactor ( {
10
+ refactorName : "Extract Symbol" ,
11
+ actionName : "function_scope_0" ,
12
+ actionDescription : "Extract to function in global scope" ,
13
+ newContent :
14
+ `const foo = /*RENAME*/newFunction()
15
+
16
+ function newFunction() {
17
+ return {
18
+ a: 1,
19
+ b: () => { return 1; }
20
+ };
21
+ }
22
+ `
23
+ } ) ;
Original file line number Diff line number Diff line change
1
+ /// <reference path='fourslash.ts' />
2
+
3
+ ////function bar(fn: () => void) {}
4
+ ////
5
+ ////class Foo {
6
+ //// x: number;
7
+ //// foo() {
8
+ //// /*start*/bar(() => {
9
+ //// () => {
10
+ //// () => {
11
+ //// this.x;
12
+ //// }
13
+ //// }
14
+ //// });/*end*/
15
+ //// }
16
+ //// }
17
+
18
+ goTo . select ( "start" , "end" ) ;
19
+ verify . refactorAvailable ( "Extract Symbol" , "function_scope_1" ) ;
20
+ verify . not . refactorAvailable ( "Extract Symbol" , "function_scope_2" ) ;
You can’t perform that action at this time.
0 commit comments