@@ -37,13 +37,13 @@ namespace ts.refactor.extractSymbol {
37
37
const usedConstantNames : Map < boolean > = createMap ( ) ;
38
38
39
39
let i = 0 ;
40
- for ( const extraction of extractions ) {
40
+ for ( const { functionExtraction , constantExtraction } of extractions ) {
41
41
// Skip these since we don't have a way to report errors yet
42
- if ( extraction . functionErrors . length === 0 ) {
42
+ if ( functionExtraction . errors . length === 0 ) {
43
43
// Don't issue refactorings with duplicated names.
44
44
// Scopes come back in "innermost first" order, so extractions will
45
45
// preferentially go into nearer scopes
46
- const description = formatStringFromArgs ( Diagnostics . Extract_to_0_in_1 . message , [ extraction . functionDescription , extraction . functionScopeDescription ] ) ;
46
+ const description = formatStringFromArgs ( Diagnostics . Extract_to_0_in_1 . message , [ functionExtraction . description , functionExtraction . scopeDescription ] ) ;
47
47
if ( ! usedFunctionNames . has ( description ) ) {
48
48
usedFunctionNames . set ( description , true ) ;
49
49
functionActions . push ( {
@@ -54,11 +54,11 @@ namespace ts.refactor.extractSymbol {
54
54
}
55
55
56
56
// Skip these since we don't have a way to report errors yet
57
- if ( extraction . constantErrors . length === 0 ) {
57
+ if ( constantExtraction . errors . length === 0 ) {
58
58
// Don't issue refactorings with duplicated names.
59
59
// Scopes come back in "innermost first" order, so extractions will
60
60
// preferentially go into nearer scopes
61
- const description = formatStringFromArgs ( Diagnostics . Extract_to_0_in_1 . message , [ extraction . constantDescription , extraction . constantScopeDescription ] ) ;
61
+ const description = formatStringFromArgs ( Diagnostics . Extract_to_0_in_1 . message , [ constantExtraction . description , constantExtraction . scopeDescription ] ) ;
62
62
if ( ! usedConstantNames . has ( description ) ) {
63
63
usedConstantNames . set ( description , true ) ;
64
64
constantActions . push ( {
@@ -521,37 +521,44 @@ namespace ts.refactor.extractSymbol {
521
521
return extractConstantInScope ( expression , scopes [ requestedChangesIndex ] , usagesPerScope [ requestedChangesIndex ] , targetRange . facts , context ) ;
522
522
}
523
523
524
- interface PossibleExtraction {
525
- readonly functionDescription : string ;
526
- readonly functionScopeDescription : string ;
527
- readonly functionErrors : ReadonlyArray < Diagnostic > ;
528
- readonly constantDescription : string ;
529
- readonly constantScopeDescription : string ;
530
- readonly constantErrors : ReadonlyArray < Diagnostic > ;
524
+ interface Extraction {
525
+ readonly description : string ;
526
+ readonly scopeDescription : string ;
527
+ readonly errors : ReadonlyArray < Diagnostic > ;
528
+ }
529
+
530
+ interface ScopeExtractions {
531
+ readonly functionExtraction : Extraction ;
532
+ readonly constantExtraction : Extraction ;
531
533
}
534
+
532
535
/**
533
536
* Given a piece of text to extract ('targetRange'), computes a list of possible extractions.
534
537
* Each returned ExtractResultForScope corresponds to a possible target scope and is either a set of changes
535
538
* or an error explaining why we can't extract into that scope.
536
539
*/
537
- function getPossibleExtractions ( targetRange : TargetRange , context : RefactorContext ) : ReadonlyArray < PossibleExtraction > | undefined {
540
+ function getPossibleExtractions ( targetRange : TargetRange , context : RefactorContext ) : ReadonlyArray < ScopeExtractions > | undefined {
538
541
const { scopes, readsAndWrites : { functionErrorsPerScope, constantErrorsPerScope } } = getPossibleExtractionsWorker ( targetRange , context ) ;
539
542
// Need the inner type annotation to avoid https://github.com/Microsoft/TypeScript/issues/7547
540
- const extractions = scopes . map ( ( scope , i ) : PossibleExtraction => {
543
+ const extractions = scopes . map ( ( scope , i ) : ScopeExtractions => {
541
544
const scopeDescription = isFunctionLikeDeclaration ( scope )
542
545
? getDescriptionForFunctionLikeDeclaration ( scope )
543
546
: isClassLike ( scope )
544
547
? getDescriptionForClassLikeDeclaration ( scope )
545
548
: getDescriptionForModuleLikeDeclaration ( scope ) ;
546
549
return {
547
- functionDescription : getDescriptionForFunctionInScope ( scope ) ,
548
- functionErrors : functionErrorsPerScope [ i ] ,
549
- functionScopeDescription : scopeDescription ,
550
- constantDescription : getDescriptionForConstantInScope ( scope ) ,
551
- constantErrors : constantErrorsPerScope [ i ] ,
552
- constantScopeDescription : ( i === 0 && ! isClassLike ( scope ) )
553
- ? "enclosing scope" // Like "global scope" and "module scope", this is not localized.
554
- : scopeDescription ,
550
+ functionExtraction : {
551
+ description : getDescriptionForFunctionInScope ( scope ) ,
552
+ errors : functionErrorsPerScope [ i ] ,
553
+ scopeDescription,
554
+ } ,
555
+ constantExtraction : {
556
+ description : getDescriptionForConstantInScope ( scope ) ,
557
+ errors : constantErrorsPerScope [ i ] ,
558
+ scopeDescription : ( i === 0 && ! isClassLike ( scope ) )
559
+ ? "enclosing scope" // Like "global scope" and "module scope", this is not localized.
560
+ : scopeDescription ,
561
+ } ,
555
562
} ;
556
563
} ) ;
557
564
return extractions ;
0 commit comments