@@ -41,12 +41,12 @@ import {
4141 flatMap ,
4242 flatMapIterator ,
4343 forEachExternalModuleToImportFrom ,
44+ forEachNameOfDefaultExport ,
4445 formatting ,
4546 FutureSourceFile ,
4647 FutureSymbolExportInfo ,
4748 getAllowSyntheticDefaultImports ,
4849 getBaseFileName ,
49- getDefaultExportInfoWorker ,
5050 getDefaultLikeExportInfo ,
5151 getDirectoryPath ,
5252 getEmitModuleFormatOfFileWorker ,
@@ -55,7 +55,6 @@ import {
5555 getEmitScriptTarget ,
5656 getExportInfoMap ,
5757 getImpliedNodeFormatForEmitWorker ,
58- getMeaningFromDeclaration ,
5958 getMeaningFromLocation ,
6059 getNameForExportedSymbol ,
6160 getOutputExtension ,
@@ -71,6 +70,7 @@ import {
7170 hasJSFileExtension ,
7271 hostGetCanonicalFileName ,
7372 Identifier ,
73+ identity ,
7474 ImportClause ,
7575 ImportEqualsDeclaration ,
7676 importFromModuleSpecifier ,
@@ -81,8 +81,6 @@ import {
8181 isExternalModuleReference ,
8282 isFullSourceFile ,
8383 isIdentifier ,
84- isIdentifierPart ,
85- isIdentifierStart ,
8684 isImportableFile ,
8785 isImportDeclaration ,
8886 isImportEqualsDeclaration ,
@@ -96,7 +94,6 @@ import {
9694 isNamespaceImport ,
9795 isRequireVariableStatement ,
9896 isSourceFileJS ,
99- isStringANonContextualKeyword ,
10097 isStringLiteral ,
10198 isStringLiteralLike ,
10299 isTypeOnlyImportDeclaration ,
@@ -114,6 +111,7 @@ import {
114111 ModuleKind ,
115112 moduleResolutionUsesNodeModules ,
116113 moduleSpecifiers ,
114+ moduleSymbolToValidIdentifier ,
117115 MultiMap ,
118116 Mutable ,
119117 NamedImports ,
@@ -129,12 +127,9 @@ import {
129127 pathIsBareSpecifier ,
130128 Program ,
131129 QuotePreference ,
132- removeFileExtension ,
133- removeSuffix ,
134130 RequireOrImportCall ,
135131 RequireVariableStatement ,
136132 sameMap ,
137- ScriptTarget ,
138133 SemanticMeaning ,
139134 shouldUseUriStyleNodeCoreModules ,
140135 single ,
@@ -873,7 +868,6 @@ function getAllExportInfoForSymbol(importingFile: SourceFile | FutureSourceFile,
873868}
874869
875870function getSingleExportInfoForSymbol ( symbol : Symbol , symbolName : string , moduleSymbol : Symbol , program : Program , host : LanguageServiceHost ) : SymbolExportInfo {
876- const compilerOptions = program . getCompilerOptions ( ) ;
877871 const mainProgramInfo = getInfoWithChecker ( program . getTypeChecker ( ) , /*isFromPackageJson*/ false ) ;
878872 if ( mainProgramInfo ) {
879873 return mainProgramInfo ;
@@ -882,7 +876,7 @@ function getSingleExportInfoForSymbol(symbol: Symbol, symbolName: string, module
882876 return Debug . checkDefined ( autoImportProvider && getInfoWithChecker ( autoImportProvider , /*isFromPackageJson*/ true ) , `Could not find symbol in specified module for code actions` ) ;
883877
884878 function getInfoWithChecker ( checker : TypeChecker , isFromPackageJson : boolean ) : SymbolExportInfo | undefined {
885- const defaultInfo = getDefaultLikeExportInfo ( moduleSymbol , checker , compilerOptions ) ;
879+ const defaultInfo = getDefaultLikeExportInfo ( moduleSymbol , checker ) ;
886880 if ( defaultInfo && skipAlias ( defaultInfo . symbol , checker ) === symbol ) {
887881 return { symbol : defaultInfo . symbol , moduleSymbol, moduleFileName : undefined , exportKind : defaultInfo . exportKind , targetFlags : skipAlias ( symbol , checker ) . flags , isFromPackageJson } ;
888882 }
@@ -1194,7 +1188,7 @@ function getNewImportFixes(
11941188 const exportEquals = checker . resolveExternalModuleSymbol ( exportInfo . moduleSymbol ) ;
11951189 let namespacePrefix ;
11961190 if ( exportEquals !== exportInfo . moduleSymbol ) {
1197- namespacePrefix = getDefaultExportInfoWorker ( exportEquals , checker , compilerOptions ) ?. name ;
1191+ namespacePrefix = forEachNameOfDefaultExport ( exportEquals , checker , compilerOptions , /*preferCapitalizedNames*/ false , identity ) ! ;
11981192 }
11991193 namespacePrefix ||= moduleSymbolToValidIdentifier (
12001194 exportInfo . moduleSymbol ,
@@ -1533,14 +1527,18 @@ function getExportInfos(
15331527 cancellationToken . throwIfCancellationRequested ( ) ;
15341528
15351529 const compilerOptions = program . getCompilerOptions ( ) ;
1536- const defaultInfo = getDefaultLikeExportInfo ( moduleSymbol , checker , compilerOptions ) ;
1537- if ( defaultInfo && ( defaultInfo . name === symbolName || moduleSymbolToValidIdentifier ( moduleSymbol , getEmitScriptTarget ( compilerOptions ) , isJsxTagName ) === symbolName ) && symbolHasMeaning ( defaultInfo . resolvedSymbol , currentTokenMeaning ) ) {
1530+ const defaultInfo = getDefaultLikeExportInfo ( moduleSymbol , checker ) ;
1531+ if (
1532+ defaultInfo
1533+ && symbolFlagsHaveMeaning ( checker . getSymbolFlags ( defaultInfo . symbol ) , currentTokenMeaning )
1534+ && forEachNameOfDefaultExport ( defaultInfo . symbol , checker , compilerOptions , isJsxTagName , name => name === symbolName )
1535+ ) {
15381536 addSymbol ( moduleSymbol , sourceFile , defaultInfo . symbol , defaultInfo . exportKind , program , isFromPackageJson ) ;
15391537 }
15401538
15411539 // check exports with the same name
15421540 const exportSymbolWithIdenticalName = checker . tryGetMemberInModuleExportsAndProperties ( symbolName , moduleSymbol ) ;
1543- if ( exportSymbolWithIdenticalName && symbolHasMeaning ( exportSymbolWithIdenticalName , currentTokenMeaning ) ) {
1541+ if ( exportSymbolWithIdenticalName && symbolFlagsHaveMeaning ( checker . getSymbolFlags ( exportSymbolWithIdenticalName ) , currentTokenMeaning ) ) {
15441542 addSymbol ( moduleSymbol , sourceFile , exportSymbolWithIdenticalName , ExportKind . Named , program , isFromPackageJson ) ;
15451543 }
15461544 } ) ;
@@ -2009,44 +2007,12 @@ function createConstEqualsRequireDeclaration(name: string | ObjectBindingPattern
20092007 ) as RequireVariableStatement ;
20102008}
20112009
2012- function symbolHasMeaning ( { declarations } : Symbol , meaning : SemanticMeaning ) : boolean {
2013- return some ( declarations , decl => ! ! ( getMeaningFromDeclaration ( decl ) & meaning ) ) ;
2014- }
2015-
2016- /** @internal */
2017- export function moduleSymbolToValidIdentifier ( moduleSymbol : Symbol , target : ScriptTarget | undefined , forceCapitalize : boolean ) : string {
2018- return moduleSpecifierToValidIdentifier ( removeFileExtension ( stripQuotes ( moduleSymbol . name ) ) , target , forceCapitalize ) ;
2019- }
2020-
2021- /** @internal */
2022- export function moduleSpecifierToValidIdentifier ( moduleSpecifier : string , target : ScriptTarget | undefined , forceCapitalize ?: boolean ) : string {
2023- const baseName = getBaseFileName ( removeSuffix ( moduleSpecifier , "/index" ) ) ;
2024- let res = "" ;
2025- let lastCharWasValid = true ;
2026- const firstCharCode = baseName . charCodeAt ( 0 ) ;
2027- if ( isIdentifierStart ( firstCharCode , target ) ) {
2028- res += String . fromCharCode ( firstCharCode ) ;
2029- if ( forceCapitalize ) {
2030- res = res . toUpperCase ( ) ;
2031- }
2032- }
2033- else {
2034- lastCharWasValid = false ;
2035- }
2036- for ( let i = 1 ; i < baseName . length ; i ++ ) {
2037- const ch = baseName . charCodeAt ( i ) ;
2038- const isValid = isIdentifierPart ( ch , target ) ;
2039- if ( isValid ) {
2040- let char = String . fromCharCode ( ch ) ;
2041- if ( ! lastCharWasValid ) {
2042- char = char . toUpperCase ( ) ;
2043- }
2044- res += char ;
2045- }
2046- lastCharWasValid = isValid ;
2047- }
2048- // Need `|| "_"` to ensure result isn't empty.
2049- return ! isStringANonContextualKeyword ( res ) ? res || "_" : `_${ res } ` ;
2010+ function symbolFlagsHaveMeaning ( flags : SymbolFlags , meaning : SemanticMeaning ) : boolean {
2011+ return meaning === SemanticMeaning . All ? true :
2012+ meaning & SemanticMeaning . Value ? ! ! ( flags & SymbolFlags . Value ) :
2013+ meaning & SemanticMeaning . Type ? ! ! ( flags & SymbolFlags . Type ) :
2014+ meaning & SemanticMeaning . Namespace ? ! ! ( flags & SymbolFlags . Namespace ) :
2015+ false ;
20502016}
20512017
20522018function getImpliedNodeFormatForEmit ( file : SourceFile | FutureSourceFile , program : Program ) {
0 commit comments