@@ -1048,7 +1048,7 @@ namespace ts.refactor.extractSymbol {
1048
1048
}
1049
1049
}
1050
1050
1051
- function transformFunctionBody ( body : Node , writes : ReadonlyArray < UsageEntry > , substitutions : ReadonlyMap < Node > , hasReturn : boolean ) : { body : Block , returnValueProperty : string } {
1051
+ function transformFunctionBody ( body : Node , writes : ReadonlyArray < UsageEntry > , substitutions : ReadonlyMap < ( ) => Node > , hasReturn : boolean ) : { body : Block , returnValueProperty : string } {
1052
1052
if ( isBlock ( body ) && ! writes && substitutions . size === 0 ) {
1053
1053
// already block, no writes to propagate back, no substitutions - can use node as is
1054
1054
return { body : createBlock ( body . statements , /*multLine*/ true ) , returnValueProperty : undefined } ;
@@ -1096,21 +1096,21 @@ namespace ts.refactor.extractSymbol {
1096
1096
const oldIgnoreReturns = ignoreReturns ;
1097
1097
ignoreReturns = ignoreReturns || isFunctionLikeDeclaration ( node ) || isClassLike ( node ) ;
1098
1098
const substitution = substitutions . get ( getNodeId ( node ) . toString ( ) ) ;
1099
- const result = substitution || visitEachChild ( node , visitor , nullTransformationContext ) ;
1099
+ const result = substitution ? substitution ( ) : visitEachChild ( node , visitor , nullTransformationContext ) ;
1100
1100
ignoreReturns = oldIgnoreReturns ;
1101
1101
return result ;
1102
1102
}
1103
1103
}
1104
1104
}
1105
1105
1106
- function transformConstantInitializer ( initializer : Expression , substitutions : ReadonlyMap < Node > ) : Expression {
1106
+ function transformConstantInitializer ( initializer : Expression , substitutions : ReadonlyMap < ( ) => Node > ) : Expression {
1107
1107
return substitutions . size
1108
1108
? visitor ( initializer ) as Expression
1109
1109
: initializer ;
1110
1110
1111
1111
function visitor ( node : Node ) : VisitResult < Node > {
1112
1112
const substitution = substitutions . get ( getNodeId ( node ) . toString ( ) ) ;
1113
- return substitution || visitEachChild ( node , visitor , nullTransformationContext ) ;
1113
+ return substitution ? substitution ( ) : visitEachChild ( node , visitor , nullTransformationContext ) ;
1114
1114
}
1115
1115
}
1116
1116
@@ -1239,7 +1239,7 @@ namespace ts.refactor.extractSymbol {
1239
1239
interface ScopeUsages {
1240
1240
readonly usages : Map < UsageEntry > ;
1241
1241
readonly typeParameterUsages : Map < TypeParameter > ; // Key is type ID
1242
- readonly substitutions : Map < Node > ;
1242
+ readonly substitutions : Map < ( ) => Node > ;
1243
1243
}
1244
1244
1245
1245
interface ReadsAndWrites {
@@ -1258,7 +1258,7 @@ namespace ts.refactor.extractSymbol {
1258
1258
1259
1259
const allTypeParameterUsages = createMap < TypeParameter > ( ) ; // Key is type ID
1260
1260
const usagesPerScope : ScopeUsages [ ] = [ ] ;
1261
- const substitutionsPerScope : Map < Node > [ ] = [ ] ;
1261
+ const substitutionsPerScope : Map < ( ) => Node > [ ] = [ ] ;
1262
1262
const functionErrorsPerScope : Diagnostic [ ] [ ] = [ ] ;
1263
1263
const constantErrorsPerScope : Diagnostic [ ] [ ] = [ ] ;
1264
1264
const visibleDeclarationsInExtractedRange : Symbol [ ] = [ ] ;
@@ -1270,8 +1270,8 @@ namespace ts.refactor.extractSymbol {
1270
1270
1271
1271
// initialize results
1272
1272
for ( const scope of scopes ) {
1273
- usagesPerScope . push ( { usages : createMap < UsageEntry > ( ) , typeParameterUsages : createMap < TypeParameter > ( ) , substitutions : createMap < Expression > ( ) } ) ;
1274
- substitutionsPerScope . push ( createMap < Expression > ( ) ) ;
1273
+ usagesPerScope . push ( { usages : createMap < UsageEntry > ( ) , typeParameterUsages : createMap < TypeParameter > ( ) , substitutions : createMap < ( ) => Expression > ( ) } ) ;
1274
+ substitutionsPerScope . push ( createMap < ( ) => Expression > ( ) ) ;
1275
1275
1276
1276
functionErrorsPerScope . push (
1277
1277
isFunctionLikeDeclaration ( scope ) && scope . kind !== SyntaxKind . FunctionDeclaration
@@ -1567,18 +1567,20 @@ namespace ts.refactor.extractSymbol {
1567
1567
}
1568
1568
}
1569
1569
1570
- function tryReplaceWithQualifiedNameOrPropertyAccess ( symbol : Symbol , scopeDecl : Node , isTypeNode : boolean ) : PropertyAccessExpression | EntityName {
1570
+ function tryReplaceWithQualifiedNameOrPropertyAccess ( symbol : Symbol , scopeDecl : Node , isTypeNode : boolean ) : ( ) => ( PropertyAccessExpression | EntityName ) {
1571
1571
if ( ! symbol ) {
1572
1572
return undefined ;
1573
1573
}
1574
1574
if ( symbol . getDeclarations ( ) . some ( d => d . parent === scopeDecl ) ) {
1575
- return createIdentifier ( symbol . name ) ;
1575
+ return ( ) => createIdentifier ( symbol . name ) ;
1576
1576
}
1577
1577
const prefix = tryReplaceWithQualifiedNameOrPropertyAccess ( symbol . parent , scopeDecl , isTypeNode ) ;
1578
1578
if ( prefix === undefined ) {
1579
1579
return undefined ;
1580
1580
}
1581
- return isTypeNode ? createQualifiedName ( < EntityName > prefix , createIdentifier ( symbol . name ) ) : createPropertyAccess ( < Expression > prefix , symbol . name ) ;
1581
+ return isTypeNode
1582
+ ? ( ) => createQualifiedName ( < EntityName > prefix ( ) , createIdentifier ( symbol . name ) )
1583
+ : ( ) => createPropertyAccess ( < Expression > prefix ( ) , symbol . name ) ;
1582
1584
}
1583
1585
}
1584
1586
0 commit comments