File tree 3 files changed +24
-4
lines changed
3 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -364,10 +364,11 @@ namespace ts.refactor.extractSymbol {
364
364
return node . expression ;
365
365
}
366
366
}
367
- else if ( isVariableStatement ( node ) ) {
367
+ else if ( isVariableStatement ( node ) || isVariableDeclarationList ( node ) ) {
368
+ const declarations = isVariableStatement ( node ) ? node . declarationList . declarations : node . declarations ;
368
369
let numInitializers = 0 ;
369
370
let lastInitializer : Expression | undefined ;
370
- for ( const declaration of node . declarationList . declarations ) {
371
+ for ( const declaration of declarations ) {
371
372
if ( declaration . initializer ) {
372
373
numInitializers ++ ;
373
374
lastInitializer = declaration . initializer ;
@@ -383,7 +384,6 @@ namespace ts.refactor.extractSymbol {
383
384
return node . initializer ;
384
385
}
385
386
}
386
-
387
387
return node ;
388
388
}
389
389
Original file line number Diff line number Diff line change @@ -191,7 +191,7 @@ namespace ts {
191
191
testExtractRange ( "extractRange28" , `[#|return [$|1|];|]` ) ;
192
192
193
193
// For statements
194
- testExtractRange ( "extractRange29" , `for ([#|var i = 1 |]; i < 2; i++) {}` ) ;
194
+ testExtractRange ( "extractRange29" , `for ([#|var i = [$|1|] |]; i < 2; i++) {}` ) ;
195
195
testExtractRange ( "extractRange30" , `for (var i = [#|[$|1|]|]; i < 2; i++) {}` ) ;
196
196
} ) ;
197
197
Original file line number Diff line number Diff line change
1
+ /// <reference path='fourslash.ts' />
2
+
3
+ // @filename : foo.ts
4
+ ////function foo() {
5
+ //// /*a*/const a = [1]/*b*/;
6
+ //// return a;
7
+ //// }
8
+
9
+ goTo . select ( "a" , "b" ) ;
10
+ edit . applyRefactor ( {
11
+ refactorName : "Extract Symbol" ,
12
+ actionName : "constant_scope_1" ,
13
+ actionDescription : "Extract to constant in global scope" ,
14
+ newContent :
15
+ `const newLocal = [1];
16
+ function foo() {
17
+ const a = /*RENAME*/newLocal;
18
+ return a;
19
+ }`
20
+ } ) ;
You can’t perform that action at this time.
0 commit comments