File tree 5 files changed +72
-2
lines changed
5 files changed +72
-2
lines changed Original file line number Diff line number Diff line change @@ -1141,7 +1141,7 @@ namespace ts.refactor.extractSymbol {
1141
1141
? undefined
1142
1142
: checker . typeToTypeNode ( checker . getContextualType ( node ) ! , scope , NodeBuilderFlags . NoTruncation ) ; // TODO: GH#18217
1143
1143
1144
- let initializer = transformConstantInitializer ( node , substitutions ) ;
1144
+ let initializer = transformConstantInitializer ( skipParentheses ( node ) , substitutions ) ;
1145
1145
1146
1146
( { variableType, initializer } = transformFunctionInitializerAndType ( variableType , initializer ) ) ;
1147
1147
@@ -1375,7 +1375,7 @@ namespace ts.refactor.extractSymbol {
1375
1375
}
1376
1376
let returnValueProperty : string | undefined ;
1377
1377
let ignoreReturns = false ;
1378
- const statements = factory . createNodeArray ( isBlock ( body ) ? body . statements . slice ( 0 ) : [ isStatement ( body ) ? body : factory . createReturnStatement ( body as Expression ) ] ) ;
1378
+ const statements = factory . createNodeArray ( isBlock ( body ) ? body . statements . slice ( 0 ) : [ isStatement ( body ) ? body : factory . createReturnStatement ( skipParentheses ( body as Expression ) ) ] ) ;
1379
1379
// rewrite body if either there are writes that should be propagated back via return statements or there are substitutions
1380
1380
if ( hasWritesOrVariableDeclarations || substitutions . size ) {
1381
1381
const rewrittenStatements = visitNodes ( statements , visitor ) . slice ( ) ;
Original file line number Diff line number Diff line change
1
+ /// <reference path='fourslash.ts' />
2
+
3
+ // @filename : foo.ts
4
+ ////const foo = 1 * /*a*/(2 + 2)/*b*/;
5
+
6
+ goTo . select ( "a" , "b" ) ;
7
+ edit . applyRefactor ( {
8
+ refactorName : "Extract Symbol" ,
9
+ actionName : "constant_scope_0" ,
10
+ actionDescription : "Extract to constant in enclosing scope" ,
11
+ newContent :
12
+ `const newLocal = 2 + 2;
13
+ const foo = 1 * /*RENAME*/newLocal;`
14
+ } ) ;
Original file line number Diff line number Diff line change
1
+ /// <reference path='fourslash.ts' />
2
+
3
+ // @filename : foo.ts
4
+ ////const foo = 1 * /*a*/(((((2 + 2)))))/*b*/;
5
+
6
+ goTo . select ( "a" , "b" ) ;
7
+ edit . applyRefactor ( {
8
+ refactorName : "Extract Symbol" ,
9
+ actionName : "constant_scope_0" ,
10
+ actionDescription : "Extract to constant in enclosing scope" ,
11
+ newContent :
12
+ `const newLocal = 2 + 2;
13
+ const foo = 1 * /*RENAME*/newLocal;`
14
+ } ) ;
Original file line number Diff line number Diff line change
1
+ /// <reference path='fourslash.ts' />
2
+
3
+ ////function foo() {
4
+ //// const x = 10 * /*a*/(10 + 10)/*b*/;
5
+ //// }
6
+
7
+ goTo . select ( "a" , "b" ) ;
8
+ edit . applyRefactor ( {
9
+ refactorName : "Extract Symbol" ,
10
+ actionName : "function_scope_1" ,
11
+ actionDescription : "Extract to function in global scope" ,
12
+ newContent :
13
+ `function foo() {
14
+ const x = 10 * /*RENAME*/newFunction();
15
+ }
16
+
17
+ function newFunction() {
18
+ return 10 + 10;
19
+ }
20
+ `
21
+ } ) ;
Original file line number Diff line number Diff line change
1
+ /// <reference path='fourslash.ts' />
2
+
3
+ ////function foo() {
4
+ //// const x = 10 * /*a*/((((((10 + 10))))))/*b*/;
5
+ //// }
6
+
7
+ goTo . select ( "a" , "b" ) ;
8
+ edit . applyRefactor ( {
9
+ refactorName : "Extract Symbol" ,
10
+ actionName : "function_scope_1" ,
11
+ actionDescription : "Extract to function in global scope" ,
12
+ newContent :
13
+ `function foo() {
14
+ const x = 10 * /*RENAME*/newFunction();
15
+ }
16
+
17
+ function newFunction() {
18
+ return 10 + 10;
19
+ }
20
+ `
21
+ } ) ;
You can’t perform that action at this time.
0 commit comments