@@ -38,7 +38,7 @@ namespace ts.Completions {
38
38
return getStringLiteralCompletionEntries ( sourceFile , position , typeChecker , compilerOptions , host , log ) ;
39
39
}
40
40
41
- const completionData = getCompletionData ( typeChecker , log , sourceFile , position , allSourceFiles , options ) ;
41
+ const completionData = getCompletionData ( typeChecker , log , sourceFile , position , allSourceFiles , options , compilerOptions . target ) ;
42
42
if ( ! completionData ) {
43
43
return undefined ;
44
44
}
@@ -135,12 +135,12 @@ namespace ts.Completions {
135
135
typeChecker : TypeChecker ,
136
136
target : ScriptTarget ,
137
137
allowStringLiteral : boolean ,
138
- origin : SymbolOriginInfo ,
138
+ origin : SymbolOriginInfo | undefined ,
139
139
) : CompletionEntry | undefined {
140
140
// Try to get a valid display name for this symbol, if we could not find one, then ignore it.
141
141
// We would like to only show things that can be added after a dot, so for instance numeric properties can
142
142
// not be accessed with a dot (a.1 <- invalid)
143
- const displayName = getCompletionEntryDisplayNameForSymbol ( symbol , target , performCharacterChecks , allowStringLiteral ) ;
143
+ const displayName = getCompletionEntryDisplayNameForSymbol ( symbol , target , performCharacterChecks , allowStringLiteral , origin ) ;
144
144
if ( ! displayName ) {
145
145
return undefined ;
146
146
}
@@ -363,7 +363,7 @@ namespace ts.Completions {
363
363
{ name, source } : CompletionEntryIdentifier ,
364
364
allSourceFiles : ReadonlyArray < SourceFile > ,
365
365
) : { type : "symbol" , symbol : Symbol , location : Node , symbolToOriginInfoMap : SymbolOriginInfoMap } | { type : "request" , request : Request } | { type : "none" } {
366
- const completionData = getCompletionData ( typeChecker , log , sourceFile , position , allSourceFiles , { includeExternalModuleExports : true } ) ;
366
+ const completionData = getCompletionData ( typeChecker , log , sourceFile , position , allSourceFiles , { includeExternalModuleExports : true } , compilerOptions . target ) ;
367
367
if ( ! completionData ) {
368
368
return { type : "none" } ;
369
369
}
@@ -377,12 +377,18 @@ namespace ts.Completions {
377
377
// We don't need to perform character checks here because we're only comparing the
378
378
// name against 'entryName' (which is known to be good), not building a new
379
379
// completion entry.
380
- const symbol = find ( symbols , s =>
381
- getCompletionEntryDisplayNameForSymbol ( s , compilerOptions . target , /*performCharacterChecks*/ false , allowStringLiteral ) === name
382
- && getSourceFromOrigin ( symbolToOriginInfoMap [ getSymbolId ( s ) ] ) === source ) ;
380
+ const symbol = find ( symbols , s => {
381
+ const origin = symbolToOriginInfoMap [ getSymbolId ( s ) ] ;
382
+ return getCompletionEntryDisplayNameForSymbol ( s , compilerOptions . target , /*performCharacterChecks*/ false , allowStringLiteral , origin ) === name
383
+ && getSourceFromOrigin ( origin ) === source ;
384
+ } ) ;
383
385
return symbol ? { type : "symbol" , symbol, location, symbolToOriginInfoMap } : { type : "none" } ;
384
386
}
385
387
388
+ function getSymbolName ( symbol : Symbol , origin : SymbolOriginInfo | undefined , target : ScriptTarget ) : string {
389
+ return origin && origin . isDefaultExport && symbol . name === "default" ? codefix . moduleSymbolToValidIdentifier ( origin . moduleSymbol , target ) : symbol . name ;
390
+ }
391
+
386
392
export interface CompletionEntryIdentifier {
387
393
name : string ;
388
394
source ?: string ;
@@ -464,7 +470,7 @@ namespace ts.Completions {
464
470
compilerOptions,
465
471
sourceFile,
466
472
rulesProvider,
467
- symbolName : symbol . name ,
473
+ symbolName : getSymbolName ( symbol , symbolOriginInfo , compilerOptions . target ) ,
468
474
getCanonicalFileName : createGetCanonicalFileName ( host . useCaseSensitiveFileNames ? host . useCaseSensitiveFileNames ( ) : false ) ,
469
475
symbolToken : undefined ,
470
476
kind : isDefaultExport ? codefix . ImportKind . Default : codefix . ImportKind . Named ,
@@ -505,6 +511,7 @@ namespace ts.Completions {
505
511
position : number ,
506
512
allSourceFiles : ReadonlyArray < SourceFile > ,
507
513
options : GetCompletionsAtPositionOptions ,
514
+ target : ScriptTarget ,
508
515
) : CompletionData | undefined {
509
516
const isJavaScriptFile = isSourceFileJavaScript ( sourceFile ) ;
510
517
@@ -903,7 +910,7 @@ namespace ts.Completions {
903
910
904
911
symbols = typeChecker . getSymbolsInScope ( scopeNode , symbolMeanings ) ;
905
912
if ( options . includeExternalModuleExports ) {
906
- getSymbolsFromOtherSourceFileExports ( symbols , previousToken && isIdentifier ( previousToken ) ? previousToken . text : "" ) ;
913
+ getSymbolsFromOtherSourceFileExports ( symbols , previousToken && isIdentifier ( previousToken ) ? previousToken . text : "" , target ) ;
907
914
}
908
915
filterGlobalCompletion ( symbols ) ;
909
916
@@ -985,7 +992,7 @@ namespace ts.Completions {
985
992
}
986
993
}
987
994
988
- function getSymbolsFromOtherSourceFileExports ( symbols : Symbol [ ] , tokenText : string ) : void {
995
+ function getSymbolsFromOtherSourceFileExports ( symbols : Symbol [ ] , tokenText : string , target : ScriptTarget ) : void {
989
996
const tokenTextLowerCase = tokenText . toLowerCase ( ) ;
990
997
991
998
codefix . forEachExternalModule ( typeChecker , allSourceFiles , moduleSymbol => {
@@ -1002,6 +1009,9 @@ namespace ts.Completions {
1002
1009
symbol = localSymbol ;
1003
1010
name = localSymbol . name ;
1004
1011
}
1012
+ else {
1013
+ name = codefix . moduleSymbolToValidIdentifier ( moduleSymbol , target ) ;
1014
+ }
1005
1015
}
1006
1016
1007
1017
if ( symbol . declarations && symbol . declarations . some ( d => isExportSpecifier ( d ) && ! ! d . parent . parent . moduleSpecifier ) ) {
@@ -1829,8 +1839,8 @@ namespace ts.Completions {
1829
1839
*
1830
1840
* @return undefined if the name is of external module
1831
1841
*/
1832
- function getCompletionEntryDisplayNameForSymbol ( symbol : Symbol , target : ScriptTarget , performCharacterChecks : boolean , allowStringLiteral : boolean ) : string | undefined {
1833
- const name = symbol . name ;
1842
+ function getCompletionEntryDisplayNameForSymbol ( symbol : Symbol , target : ScriptTarget , performCharacterChecks : boolean , allowStringLiteral : boolean , origin : SymbolOriginInfo | undefined ) : string | undefined {
1843
+ const name = getSymbolName ( symbol , origin , target ) ;
1834
1844
if ( ! name ) return undefined ;
1835
1845
1836
1846
// First check of the displayName is not external module; if it is an external module, it is not valid entry
0 commit comments