@@ -231,11 +231,11 @@ namespace ts.codefix {
231
231
function getInfoWithChecker ( checker : TypeChecker , isFromPackageJson : boolean ) : SymbolExportInfo | undefined {
232
232
const defaultInfo = getDefaultLikeExportInfo ( moduleSymbol , checker , compilerOptions ) ;
233
233
if ( defaultInfo && skipAlias ( defaultInfo . symbol , checker ) === symbol ) {
234
- return { symbol : defaultInfo . symbol , moduleSymbol, moduleFileName : undefined , exportKind : defaultInfo . exportKind , isTypeOnly : isTypeOnlySymbol ( symbol , checker ) , isFromPackageJson } ;
234
+ return { symbol : defaultInfo . symbol , moduleSymbol, moduleFileName : undefined , exportKind : defaultInfo . exportKind , targetFlags : skipAlias ( symbol , checker ) . flags , isFromPackageJson } ;
235
235
}
236
236
const named = checker . tryGetMemberInModuleExportsAndProperties ( symbol . name , moduleSymbol ) ;
237
237
if ( named && skipAlias ( named , checker ) === symbol ) {
238
- return { symbol : named , moduleSymbol, moduleFileName : undefined , exportKind : ExportKind . Named , isTypeOnly : isTypeOnlySymbol ( symbol , checker ) , isFromPackageJson } ;
238
+ return { symbol : named , moduleSymbol, moduleFileName : undefined , exportKind : ExportKind . Named , targetFlags : skipAlias ( symbol , checker ) . flags , isFromPackageJson } ;
239
239
}
240
240
}
241
241
}
@@ -256,12 +256,12 @@ namespace ts.codefix {
256
256
257
257
const defaultInfo = getDefaultLikeExportInfo ( moduleSymbol , checker , compilerOptions ) ;
258
258
if ( defaultInfo && ( defaultInfo . name === symbolName || moduleSymbolToValidIdentifier ( moduleSymbol , compilerOptions . target ) === symbolName ) && skipAlias ( defaultInfo . symbol , checker ) === exportedSymbol && isImportable ( program , moduleFile , isFromPackageJson ) ) {
259
- result . push ( { symbol : defaultInfo . symbol , moduleSymbol, moduleFileName : moduleFile ?. fileName , exportKind : defaultInfo . exportKind , isTypeOnly : isTypeOnlySymbol ( defaultInfo . symbol , checker ) , isFromPackageJson } ) ;
259
+ result . push ( { symbol : defaultInfo . symbol , moduleSymbol, moduleFileName : moduleFile ?. fileName , exportKind : defaultInfo . exportKind , targetFlags : skipAlias ( defaultInfo . symbol , checker ) . flags , isFromPackageJson } ) ;
260
260
}
261
261
262
262
for ( const exported of checker . getExportsAndPropertiesOfModule ( moduleSymbol ) ) {
263
263
if ( exported . name === symbolName && skipAlias ( exported , checker ) === exportedSymbol && isImportable ( program , moduleFile , isFromPackageJson ) ) {
264
- result . push ( { symbol : exported , moduleSymbol, moduleFileName : moduleFile ?. fileName , exportKind : ExportKind . Named , isTypeOnly : isTypeOnlySymbol ( exported , checker ) , isFromPackageJson } ) ;
264
+ result . push ( { symbol : exported , moduleSymbol, moduleFileName : moduleFile ?. fileName , exportKind : ExportKind . Named , targetFlags : skipAlias ( exported , checker ) . flags , isFromPackageJson } ) ;
265
265
}
266
266
}
267
267
} ) ;
@@ -294,10 +294,6 @@ namespace ts.codefix {
294
294
return result && { ...result , computedWithoutCacheCount } ;
295
295
}
296
296
297
- function isTypeOnlySymbol ( s : Symbol , checker : TypeChecker ) : boolean {
298
- return ! ( skipAlias ( s , checker ) . flags & SymbolFlags . Value ) ;
299
- }
300
-
301
297
function isTypeOnlyPosition ( sourceFile : SourceFile , position : number ) {
302
298
return isValidTypeOnlyAliasUseSite ( getTokenAtPosition ( sourceFile , position ) ) ;
303
299
}
@@ -395,9 +391,9 @@ namespace ts.codefix {
395
391
} ) ;
396
392
}
397
393
398
- function getExistingImportDeclarations ( { moduleSymbol, exportKind, isTypeOnly : exportedSymbolIsTypeOnly } : SymbolExportInfo , checker : TypeChecker , importingFile : SourceFile , compilerOptions : CompilerOptions ) : readonly FixAddToExistingImportInfo [ ] {
394
+ function getExistingImportDeclarations ( { moduleSymbol, exportKind, targetFlags } : SymbolExportInfo , checker : TypeChecker , importingFile : SourceFile , compilerOptions : CompilerOptions ) : readonly FixAddToExistingImportInfo [ ] {
399
395
// Can't use an es6 import for a type in JS.
400
- if ( exportedSymbolIsTypeOnly && isSourceFileJS ( importingFile ) ) return emptyArray ;
396
+ if ( ! ( targetFlags & SymbolFlags . Value ) && isSourceFileJS ( importingFile ) ) return emptyArray ;
401
397
const importKind = getImportKind ( importingFile , exportKind , compilerOptions ) ;
402
398
return mapDefined ( importingFile . imports , ( moduleSpecifier ) : FixAddToExistingImportInfo | undefined => {
403
399
const i = importFromModuleSpecifier ( moduleSpecifier ) ;
@@ -462,7 +458,7 @@ namespace ts.codefix {
462
458
computedWithoutCacheCount += computedWithoutCache ? 1 : 0 ;
463
459
return moduleSpecifiers ?. map ( ( moduleSpecifier ) : FixAddNewImport | FixUseImportType =>
464
460
// `position` should only be undefined at a missing jsx namespace, in which case we shouldn't be looking for pure types.
465
- exportInfo . isTypeOnly && isJs && position !== undefined
461
+ ! ( exportInfo . targetFlags & SymbolFlags . Value ) && isJs && position !== undefined
466
462
? { kind : ImportFixKind . ImportType , moduleSpecifier, position, exportInfo }
467
463
: {
468
464
kind : ImportFixKind . AddNew ,
@@ -547,7 +543,7 @@ namespace ts.codefix {
547
543
if ( ! umdSymbol ) return undefined ;
548
544
const symbol = checker . getAliasedSymbol ( umdSymbol ) ;
549
545
const symbolName = umdSymbol . name ;
550
- const exportInfos : readonly SymbolExportInfo [ ] = [ { symbol : umdSymbol , moduleSymbol : symbol , moduleFileName : undefined , exportKind : ExportKind . UMD , isTypeOnly : false , isFromPackageJson : false } ] ;
546
+ const exportInfos : readonly SymbolExportInfo [ ] = [ { symbol : umdSymbol , moduleSymbol : symbol , moduleFileName : undefined , exportKind : ExportKind . UMD , targetFlags : symbol . flags , isFromPackageJson : false } ] ;
551
547
const useRequire = shouldUseRequire ( sourceFile , program ) ;
552
548
const fixes = getImportFixes ( exportInfos , symbolName , isIdentifier ( token ) ? token . getStart ( sourceFile ) : undefined , /*preferTypeOnlyImport*/ false , useRequire , program , sourceFile , host , preferences ) ;
553
549
return { fixes, symbolName } ;
@@ -653,7 +649,7 @@ namespace ts.codefix {
653
649
! toFile && packageJsonFilter . allowsImportingAmbientModule ( moduleSymbol , moduleSpecifierResolutionHost )
654
650
) {
655
651
const checker = program . getTypeChecker ( ) ;
656
- originalSymbolToExportInfos . add ( getUniqueSymbolId ( exportedSymbol , checker ) . toString ( ) , { symbol : exportedSymbol , moduleSymbol, moduleFileName : toFile ?. fileName , exportKind, isTypeOnly : isTypeOnlySymbol ( exportedSymbol , checker ) , isFromPackageJson } ) ;
652
+ originalSymbolToExportInfos . add ( getUniqueSymbolId ( exportedSymbol , checker ) . toString ( ) , { symbol : exportedSymbol , moduleSymbol, moduleFileName : toFile ?. fileName , exportKind, targetFlags : skipAlias ( exportedSymbol , checker ) . flags , isFromPackageJson } ) ;
657
653
}
658
654
}
659
655
forEachExternalModuleToImportFrom ( program , host , useAutoImportProvider , ( moduleSymbol , sourceFile , program , isFromPackageJson ) => {
0 commit comments