@@ -39,7 +39,7 @@ namespace ts.Completions {
39
39
return getStringLiteralCompletionEntries ( sourceFile , position , typeChecker , compilerOptions , host , log ) ;
40
40
}
41
41
42
- const completionData = getCompletionData ( typeChecker , log , sourceFile , position , allSourceFiles , options ) ;
42
+ const completionData = getCompletionData ( typeChecker , log , sourceFile , position , allSourceFiles , options , compilerOptions . target ) ;
43
43
if ( ! completionData ) {
44
44
return undefined ;
45
45
}
@@ -136,12 +136,12 @@ namespace ts.Completions {
136
136
typeChecker : TypeChecker ,
137
137
target : ScriptTarget ,
138
138
allowStringLiteral : boolean ,
139
- origin : SymbolOriginInfo ,
139
+ origin : SymbolOriginInfo | undefined ,
140
140
) : CompletionEntry | undefined {
141
141
// Try to get a valid display name for this symbol, if we could not find one, then ignore it.
142
142
// We would like to only show things that can be added after a dot, so for instance numeric properties can
143
143
// not be accessed with a dot (a.1 <- invalid)
144
- const displayName = getCompletionEntryDisplayNameForSymbol ( symbol , target , performCharacterChecks , allowStringLiteral ) ;
144
+ const displayName = getCompletionEntryDisplayNameForSymbol ( symbol , target , performCharacterChecks , allowStringLiteral , origin ) ;
145
145
if ( ! displayName ) {
146
146
return undefined ;
147
147
}
@@ -381,7 +381,7 @@ namespace ts.Completions {
381
381
{ name, source } : CompletionEntryIdentifier ,
382
382
allSourceFiles : ReadonlyArray < SourceFile > ,
383
383
) : { type : "symbol" , symbol : Symbol , location : Node , symbolToOriginInfoMap : SymbolOriginInfoMap } | { type : "request" , request : Request } | { type : "none" } {
384
- const completionData = getCompletionData ( typeChecker , log , sourceFile , position , allSourceFiles , { includeExternalModuleExports : true } ) ;
384
+ const completionData = getCompletionData ( typeChecker , log , sourceFile , position , allSourceFiles , { includeExternalModuleExports : true } , compilerOptions . target ) ;
385
385
if ( ! completionData ) {
386
386
return { type : "none" } ;
387
387
}
@@ -395,12 +395,18 @@ namespace ts.Completions {
395
395
// We don't need to perform character checks here because we're only comparing the
396
396
// name against 'entryName' (which is known to be good), not building a new
397
397
// completion entry.
398
- const symbol = find ( symbols , s =>
399
- getCompletionEntryDisplayNameForSymbol ( s , compilerOptions . target , /*performCharacterChecks*/ false , allowStringLiteral ) === name
400
- && getSourceFromOrigin ( symbolToOriginInfoMap [ getSymbolId ( s ) ] ) === source ) ;
398
+ const symbol = find ( symbols , s => {
399
+ const origin = symbolToOriginInfoMap [ getSymbolId ( s ) ] ;
400
+ return getCompletionEntryDisplayNameForSymbol ( s , compilerOptions . target , /*performCharacterChecks*/ false , allowStringLiteral , origin ) === name
401
+ && getSourceFromOrigin ( origin ) === source ;
402
+ } ) ;
401
403
return symbol ? { type : "symbol" , symbol, location, symbolToOriginInfoMap } : { type : "none" } ;
402
404
}
403
405
406
+ function getSymbolName ( symbol : Symbol , origin : SymbolOriginInfo | undefined , target : ScriptTarget ) : string {
407
+ return origin && origin . isDefaultExport && symbol . name === "default" ? codefix . moduleSymbolToValidIdentifier ( origin . moduleSymbol , target ) : symbol . name ;
408
+ }
409
+
404
410
export interface CompletionEntryIdentifier {
405
411
name : string ;
406
412
source ?: string ;
@@ -482,7 +488,7 @@ namespace ts.Completions {
482
488
compilerOptions,
483
489
sourceFile,
484
490
formatContext,
485
- symbolName : symbol . name ,
491
+ symbolName : getSymbolName ( symbol , symbolOriginInfo , compilerOptions . target ) ,
486
492
getCanonicalFileName : createGetCanonicalFileName ( host . useCaseSensitiveFileNames ? host . useCaseSensitiveFileNames ( ) : false ) ,
487
493
symbolToken : undefined ,
488
494
kind : isDefaultExport ? codefix . ImportKind . Default : codefix . ImportKind . Named ,
@@ -523,6 +529,7 @@ namespace ts.Completions {
523
529
position : number ,
524
530
allSourceFiles : ReadonlyArray < SourceFile > ,
525
531
options : GetCompletionsAtPositionOptions ,
532
+ target : ScriptTarget ,
526
533
) : CompletionData | undefined {
527
534
const isJavaScriptFile = isSourceFileJavaScript ( sourceFile ) ;
528
535
@@ -921,7 +928,7 @@ namespace ts.Completions {
921
928
922
929
symbols = typeChecker . getSymbolsInScope ( scopeNode , symbolMeanings ) ;
923
930
if ( options . includeExternalModuleExports ) {
924
- getSymbolsFromOtherSourceFileExports ( symbols , previousToken && isIdentifier ( previousToken ) ? previousToken . text : "" ) ;
931
+ getSymbolsFromOtherSourceFileExports ( symbols , previousToken && isIdentifier ( previousToken ) ? previousToken . text : "" , target ) ;
925
932
}
926
933
filterGlobalCompletion ( symbols ) ;
927
934
@@ -1003,7 +1010,7 @@ namespace ts.Completions {
1003
1010
}
1004
1011
}
1005
1012
1006
- function getSymbolsFromOtherSourceFileExports ( symbols : Symbol [ ] , tokenText : string ) : void {
1013
+ function getSymbolsFromOtherSourceFileExports ( symbols : Symbol [ ] , tokenText : string , target : ScriptTarget ) : void {
1007
1014
const tokenTextLowerCase = tokenText . toLowerCase ( ) ;
1008
1015
1009
1016
codefix . forEachExternalModule ( typeChecker , allSourceFiles , moduleSymbol => {
@@ -1020,6 +1027,9 @@ namespace ts.Completions {
1020
1027
symbol = localSymbol ;
1021
1028
name = localSymbol . name ;
1022
1029
}
1030
+ else {
1031
+ name = codefix . moduleSymbolToValidIdentifier ( moduleSymbol , target ) ;
1032
+ }
1023
1033
}
1024
1034
1025
1035
if ( symbol . declarations && symbol . declarations . some ( d => isExportSpecifier ( d ) && ! ! d . parent . parent . moduleSpecifier ) ) {
@@ -1847,8 +1857,8 @@ namespace ts.Completions {
1847
1857
*
1848
1858
* @return undefined if the name is of external module
1849
1859
*/
1850
- function getCompletionEntryDisplayNameForSymbol ( symbol : Symbol , target : ScriptTarget , performCharacterChecks : boolean , allowStringLiteral : boolean ) : string | undefined {
1851
- const name = symbol . name ;
1860
+ function getCompletionEntryDisplayNameForSymbol ( symbol : Symbol , target : ScriptTarget , performCharacterChecks : boolean , allowStringLiteral : boolean , origin : SymbolOriginInfo | undefined ) : string | undefined {
1861
+ const name = getSymbolName ( symbol , origin , target ) ;
1852
1862
if ( ! name ) return undefined ;
1853
1863
1854
1864
// First check of the displayName is not external module; if it is an external module, it is not valid entry
0 commit comments