@@ -39,7 +39,7 @@ namespace ts.Completions {
3939 return getStringLiteralCompletionEntries ( sourceFile , position , typeChecker , compilerOptions , host , log ) ;
4040 }
4141
42- const completionData = getCompletionData ( typeChecker , log , sourceFile , position , allSourceFiles , options ) ;
42+ const completionData = getCompletionData ( typeChecker , log , sourceFile , position , allSourceFiles , options , compilerOptions . target ) ;
4343 if ( ! completionData ) {
4444 return undefined ;
4545 }
@@ -136,12 +136,12 @@ namespace ts.Completions {
136136 typeChecker : TypeChecker ,
137137 target : ScriptTarget ,
138138 allowStringLiteral : boolean ,
139- origin : SymbolOriginInfo ,
139+ origin : SymbolOriginInfo | undefined ,
140140 ) : CompletionEntry | undefined {
141141 // Try to get a valid display name for this symbol, if we could not find one, then ignore it.
142142 // We would like to only show things that can be added after a dot, so for instance numeric properties can
143143 // 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 ) ;
145145 if ( ! displayName ) {
146146 return undefined ;
147147 }
@@ -381,7 +381,7 @@ namespace ts.Completions {
381381 { name, source } : CompletionEntryIdentifier ,
382382 allSourceFiles : ReadonlyArray < SourceFile > ,
383383 ) : { 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 ) ;
385385 if ( ! completionData ) {
386386 return { type : "none" } ;
387387 }
@@ -395,12 +395,18 @@ namespace ts.Completions {
395395 // We don't need to perform character checks here because we're only comparing the
396396 // name against 'entryName' (which is known to be good), not building a new
397397 // 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+ } ) ;
401403 return symbol ? { type : "symbol" , symbol, location, symbolToOriginInfoMap } : { type : "none" } ;
402404 }
403405
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+
404410 export interface CompletionEntryIdentifier {
405411 name : string ;
406412 source ?: string ;
@@ -482,7 +488,7 @@ namespace ts.Completions {
482488 compilerOptions,
483489 sourceFile,
484490 formatContext,
485- symbolName : symbol . name ,
491+ symbolName : getSymbolName ( symbol , symbolOriginInfo , compilerOptions . target ) ,
486492 getCanonicalFileName : createGetCanonicalFileName ( host . useCaseSensitiveFileNames ? host . useCaseSensitiveFileNames ( ) : false ) ,
487493 symbolToken : undefined ,
488494 kind : isDefaultExport ? codefix . ImportKind . Default : codefix . ImportKind . Named ,
@@ -523,6 +529,7 @@ namespace ts.Completions {
523529 position : number ,
524530 allSourceFiles : ReadonlyArray < SourceFile > ,
525531 options : GetCompletionsAtPositionOptions ,
532+ target : ScriptTarget ,
526533 ) : CompletionData | undefined {
527534 const isJavaScriptFile = isSourceFileJavaScript ( sourceFile ) ;
528535
@@ -921,7 +928,7 @@ namespace ts.Completions {
921928
922929 symbols = typeChecker . getSymbolsInScope ( scopeNode , symbolMeanings ) ;
923930 if ( options . includeExternalModuleExports ) {
924- getSymbolsFromOtherSourceFileExports ( symbols , previousToken && isIdentifier ( previousToken ) ? previousToken . text : "" ) ;
931+ getSymbolsFromOtherSourceFileExports ( symbols , previousToken && isIdentifier ( previousToken ) ? previousToken . text : "" , target ) ;
925932 }
926933 filterGlobalCompletion ( symbols ) ;
927934
@@ -1003,7 +1010,7 @@ namespace ts.Completions {
10031010 }
10041011 }
10051012
1006- function getSymbolsFromOtherSourceFileExports ( symbols : Symbol [ ] , tokenText : string ) : void {
1013+ function getSymbolsFromOtherSourceFileExports ( symbols : Symbol [ ] , tokenText : string , target : ScriptTarget ) : void {
10071014 const tokenTextLowerCase = tokenText . toLowerCase ( ) ;
10081015
10091016 codefix . forEachExternalModule ( typeChecker , allSourceFiles , moduleSymbol => {
@@ -1020,6 +1027,9 @@ namespace ts.Completions {
10201027 symbol = localSymbol ;
10211028 name = localSymbol . name ;
10221029 }
1030+ else {
1031+ name = codefix . moduleSymbolToValidIdentifier ( moduleSymbol , target ) ;
1032+ }
10231033 }
10241034
10251035 if ( symbol . declarations && symbol . declarations . some ( d => isExportSpecifier ( d ) && ! ! d . parent . parent . moduleSpecifier ) ) {
@@ -1847,8 +1857,8 @@ namespace ts.Completions {
18471857 *
18481858 * @return undefined if the name is of external module
18491859 */
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 ) ;
18521862 if ( ! name ) return undefined ;
18531863
18541864 // First check of the displayName is not external module; if it is an external module, it is not valid entry
0 commit comments