@@ -28,7 +28,7 @@ namespace ts.refactor.extractSymbol {
28
28
const usedConstantNames : Map < boolean > = createMap ( ) ;
29
29
30
30
let i = 0 ;
31
- for ( const { functionExtraction, constantExtraction} of extractions ) {
31
+ for ( const { functionExtraction, constantExtraction } of extractions ) {
32
32
// Skip these since we don't have a way to report errors yet
33
33
if ( functionExtraction . errors . length === 0 ) {
34
34
// Don't issue refactorings with duplicated names.
@@ -1103,7 +1103,12 @@ namespace ts.refactor.extractSymbol {
1103
1103
changeTracker . delete ( context . file , node . parent ) ;
1104
1104
}
1105
1105
else {
1106
- const localReference = createIdentifier ( localNameText ) ;
1106
+ let localReference : Expression = createIdentifier ( localNameText ) ;
1107
+ // When extract to a new variable in JSX content, need to wrap a {} out of the new variable
1108
+ // or it will become a plain text
1109
+ if ( isInJSXContent ( node ) ) {
1110
+ localReference = createJsxExpression ( /*dotDotDotToken*/ undefined , localReference ) ;
1111
+ }
1107
1112
changeTracker . replaceNode ( context . file , node , localReference ) ;
1108
1113
}
1109
1114
}
@@ -1115,6 +1120,12 @@ namespace ts.refactor.extractSymbol {
1115
1120
const renameLocation = getRenameLocation ( edits , renameFilename , localNameText , /*isDeclaredBeforeUse*/ true ) ;
1116
1121
return { renameFilename, renameLocation, edits } ;
1117
1122
1123
+ function isInJSXContent ( node : Node ) {
1124
+ if ( ! isJsxElement ( node ) ) return false ;
1125
+ if ( isJsxElement ( node . parent ) ) return true ;
1126
+ return false ;
1127
+ }
1128
+
1118
1129
function transformFunctionInitializerAndType ( variableType : TypeNode | undefined , initializer : Expression ) : { variableType : TypeNode | undefined , initializer : Expression } {
1119
1130
// If no contextual type exists there is nothing to transfer to the function signature
1120
1131
if ( variableType === undefined ) return { variableType, initializer } ;
@@ -1215,8 +1226,8 @@ namespace ts.refactor.extractSymbol {
1215
1226
}
1216
1227
1217
1228
function compareTypesByDeclarationOrder (
1218
- { type : type1 , declaration : declaration1 } : { type : Type , declaration ?: Declaration } ,
1219
- { type : type2 , declaration : declaration2 } : { type : Type , declaration ?: Declaration } ) {
1229
+ { type : type1 , declaration : declaration1 } : { type : Type , declaration ?: Declaration } ,
1230
+ { type : type2 , declaration : declaration2 } : { type : Type , declaration ?: Declaration } ) {
1220
1231
1221
1232
return compareProperties ( declaration1 , declaration2 , "pos" , compareValues )
1222
1233
|| compareStringsCaseSensitive (
@@ -1621,7 +1632,7 @@ namespace ts.refactor.extractSymbol {
1621
1632
// a lot of properties, each of which the walker will visit. Unfortunately, the
1622
1633
// solution isn't as trivial as filtering to user types because of (e.g.) Array.
1623
1634
const symbolWalker = checker . getSymbolWalker ( ( ) => ( cancellationToken . throwIfCancellationRequested ( ) , true ) ) ;
1624
- const { visitedTypes} = symbolWalker . walkType ( type ) ;
1635
+ const { visitedTypes } = symbolWalker . walkType ( type ) ;
1625
1636
1626
1637
for ( const visitedType of visitedTypes ) {
1627
1638
if ( visitedType . isTypeParameter ( ) ) {
0 commit comments