@@ -167,7 +167,7 @@ namespace ts.Completions {
167
167
origin : SymbolOriginInfo | undefined ,
168
168
recommendedCompletion : Symbol | undefined ,
169
169
propertyAccessToConvert : PropertyAccessExpression | undefined ,
170
- isJsxInitializer : boolean ,
170
+ isJsxInitializer : IsJsxInitializer ,
171
171
includeInsertTextCompletions : boolean ,
172
172
) : CompletionEntry | undefined {
173
173
const info = getCompletionEntryDisplayNameForSymbol ( symbol , target , origin , kind ) ;
@@ -193,6 +193,9 @@ namespace ts.Completions {
193
193
if ( isJsxInitializer ) {
194
194
if ( insertText === undefined ) insertText = name ;
195
195
insertText = `{${ insertText } }` ;
196
+ if ( typeof isJsxInitializer !== "boolean" ) {
197
+ replacementSpan = createTextSpanFromNode ( isJsxInitializer , sourceFile ) ;
198
+ }
196
199
}
197
200
}
198
201
@@ -250,7 +253,7 @@ namespace ts.Completions {
250
253
kind : CompletionKind ,
251
254
includeInsertTextCompletions ?: boolean ,
252
255
propertyAccessToConvert ?: PropertyAccessExpression | undefined ,
253
- isJsxInitializer ?: boolean ,
256
+ isJsxInitializer ?: IsJsxInitializer ,
254
257
recommendedCompletion ?: Symbol ,
255
258
symbolToOriginInfoMap ?: SymbolOriginInfoMap ,
256
259
) : Map < true > {
@@ -499,7 +502,7 @@ namespace ts.Completions {
499
502
location : Node ;
500
503
symbolToOriginInfoMap : SymbolOriginInfoMap ;
501
504
previousToken : Node ;
502
- readonly isJsxInitializer : boolean ;
505
+ readonly isJsxInitializer : IsJsxInitializer ;
503
506
}
504
507
function getSymbolCompletionFromEntryId (
505
508
typeChecker : TypeChecker ,
@@ -683,6 +686,8 @@ namespace ts.Completions {
683
686
}
684
687
685
688
const enum CompletionDataKind { Data , JsDocTagName , JsDocTag , JsDocParameterName }
689
+ /** true: after the `=` sign but no identifier has been typed yet. Else is the Identifier after the initializer. */
690
+ type IsJsxInitializer = boolean | Identifier ;
686
691
interface CompletionData {
687
692
readonly kind : CompletionDataKind . Data ;
688
693
readonly symbols : ReadonlyArray < Symbol > ;
@@ -695,7 +700,7 @@ namespace ts.Completions {
695
700
readonly symbolToOriginInfoMap : SymbolOriginInfoMap ;
696
701
readonly recommendedCompletion : Symbol | undefined ;
697
702
readonly previousToken : Node | undefined ;
698
- readonly isJsxInitializer : boolean ;
703
+ readonly isJsxInitializer : IsJsxInitializer ;
699
704
}
700
705
type Request = { readonly kind : CompletionDataKind . JsDocTagName | CompletionDataKind . JsDocTag } | { readonly kind : CompletionDataKind . JsDocParameterName , tag : JSDocParameterTag } ;
701
706
@@ -877,7 +882,7 @@ namespace ts.Completions {
877
882
let isRightOfDot = false ;
878
883
let isRightOfOpenTag = false ;
879
884
let isStartingCloseTag = false ;
880
- let isJsxInitializer = false ;
885
+ let isJsxInitializer : IsJsxInitializer = false ;
881
886
882
887
let location = getTouchingPropertyName ( sourceFile , position , insideJsDocTagTypeExpression ) ; // TODO: GH#15853
883
888
if ( contextToken ) {
@@ -938,7 +943,15 @@ namespace ts.Completions {
938
943
break ;
939
944
940
945
case SyntaxKind . JsxAttribute :
941
- isJsxInitializer = previousToken . kind === SyntaxKind . EqualsToken ;
946
+ switch ( previousToken . kind ) {
947
+ case SyntaxKind . EqualsToken :
948
+ isJsxInitializer = true ;
949
+ break ;
950
+ case SyntaxKind . Identifier :
951
+ if ( previousToken !== ( parent as JsxAttribute ) . name ) {
952
+ isJsxInitializer = previousToken as Identifier ;
953
+ }
954
+ }
942
955
break ;
943
956
}
944
957
}
0 commit comments