File tree Expand file tree Collapse file tree 4 files changed +42
-8
lines changed Expand file tree Collapse file tree 4 files changed +42
-8
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,13 @@ function F() {
40
40
}
41
41
` ) ;
42
42
43
+ testExtractConstant ( "extractConstant_ExpressionStatementConsumesLocal" , `
44
+ function F() {
45
+ let i = 0;
46
+ [#|i++|];
47
+ }
48
+ ` ) ;
49
+
43
50
testExtractConstant ( "extractConstant_BlockScopes_NoDependencies" ,
44
51
`for (let i = 0; i < 10; i++) {
45
52
for (let j = 0; j < 10; j++) {
Original file line number Diff line number Diff line change @@ -1351,14 +1351,13 @@ namespace ts.refactor.extractSymbol {
1351
1351
}
1352
1352
1353
1353
for ( let i = 0 ; i < scopes . length ; i ++ ) {
1354
- if ( ! isReadonlyArray ( targetRange . range ) ) {
1355
- const scopeUsages = usagesPerScope [ i ] ;
1356
- // Special case: in the innermost scope, all usages are available.
1357
- // (The computed value reflects the value at the top-level of the scope, but the
1358
- // local will actually be declared at the same level as the extracted expression).
1359
- if ( i > 0 && ( scopeUsages . usages . size > 0 || scopeUsages . typeParameterUsages . size > 0 ) ) {
1360
- constantErrorsPerScope [ i ] . push ( createDiagnosticForNode ( targetRange . range , Messages . CannotAccessVariablesFromNestedScopes ) ) ;
1361
- }
1354
+ const scopeUsages = usagesPerScope [ i ] ;
1355
+ // Special case: in the innermost scope, all usages are available.
1356
+ // (The computed value reflects the value at the top-level of the scope, but the
1357
+ // local will actually be declared at the same level as the extracted expression).
1358
+ if ( i > 0 && ( scopeUsages . usages . size > 0 || scopeUsages . typeParameterUsages . size > 0 ) ) {
1359
+ const errorNode = isReadonlyArray ( targetRange . range ) ? targetRange . range [ 0 ] : targetRange . range ;
1360
+ constantErrorsPerScope [ i ] . push ( createDiagnosticForNode ( errorNode , Messages . CannotAccessVariablesFromNestedScopes ) ) ;
1362
1361
}
1363
1362
1364
1363
let hasWrite = false ;
Original file line number Diff line number Diff line change
1
+ // ==ORIGINAL==
2
+
3
+ function F ( ) {
4
+ let i = 0 ;
5
+ i ++ ;
6
+ }
7
+
8
+ // ==SCOPE::Extract to constant in enclosing scope==
9
+
10
+ function F ( ) {
11
+ let i = 0 ;
12
+ const /*RENAME*/ newLocal = i ++ ;
13
+ }
14
+
Original file line number Diff line number Diff line change
1
+ // ==ORIGINAL==
2
+
3
+ function F ( ) {
4
+ let i = 0 ;
5
+ i ++ ;
6
+ }
7
+
8
+ // ==SCOPE::Extract to constant in enclosing scope==
9
+
10
+ function F ( ) {
11
+ let i = 0 ;
12
+ const /*RENAME*/ newLocal = i ++ ;
13
+ }
14
+
You can’t perform that action at this time.
0 commit comments