@@ -2,15 +2,14 @@ import { isBuiltin } from 'node:module';
2
2
import ts from 'typescript' ;
3
3
import { ALIAS_TAG , ANONYMOUS , DEFAULT_EXTENSIONS , IMPORT_STAR } from '../constants.js' ;
4
4
import type { Tags } from '../types/cli.js' ;
5
- import type { Export , ExportMap , ExportMember , ImportMap , UnresolvedImport } from '../types/dependency-graph.js' ;
5
+ import type { ExportMap , ExportMember , ImportMap , UnresolvedImport } from '../types/dependency-graph.js' ;
6
6
import type { ExportNode , ExportNodeMember } from '../types/exports.js' ;
7
7
import type { ImportNode } from '../types/imports.js' ;
8
8
import type { IssueSymbol } from '../types/issues.js' ;
9
9
import { timerify } from '../util/Performance.js' ;
10
10
import { addNsValue , addValue , createImports } from '../util/dependency-graph.js' ;
11
11
import { isStartsLikePackageName , sanitizeSpecifier } from '../util/modules.js' ;
12
12
import { extname , isInNodeModules } from '../util/path.js' ;
13
- import { isIdChar } from '../util/regex.js' ;
14
13
import { shouldIgnore } from '../util/tag.js' ;
15
14
import type { BoundSourceFile } from './SourceFile.js' ;
16
15
import {
@@ -25,6 +24,7 @@ import {
25
24
isImportSpecifier ,
26
25
isReferencedInExportedType ,
27
26
} from './ast-helpers.js' ;
27
+ import { findInternalReferences } from './find-internal-references.js' ;
28
28
import getDynamicImportVisitors from './visitors/dynamic-imports/index.js' ;
29
29
import getExportVisitors from './visitors/exports/index.js' ;
30
30
import { getImportsFromPragmas } from './visitors/helpers.js' ;
@@ -54,9 +54,6 @@ const createMember = (node: ts.Node, member: ExportNodeMember, pos: number): Exp
54
54
} ;
55
55
} ;
56
56
57
- const isType = ( item : Export | ExportMember ) =>
58
- item . type === 'type' || item . type === 'interface' || item . type === 'member' ;
59
-
60
57
export type GetImportsAndExportsOptions = {
61
58
skipTypeOnly : boolean ;
62
59
skipExports : boolean ;
@@ -397,59 +394,13 @@ const getImportsAndExports = (
397
394
const pragmaImports = getImportsFromPragmas ( sourceFile ) ;
398
395
if ( pragmaImports ) for ( const node of pragmaImports ) addImport ( node , sourceFile ) ;
399
396
400
- const setRefs = ( item : Export | ExportMember ) => {
401
- if ( ! item . symbol ) return ;
402
-
403
- if ( item . symbol . flags & ts . SymbolFlags . AliasExcludes ) {
404
- item . refs = [ 1 , false ] ;
405
- return ;
406
- }
407
-
408
- const symbols = new Set < ts . Symbol > ( ) ;
409
- let index = 0 ;
410
- const text = sourceFile . text ;
411
- const id = item . identifier ;
412
- // biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
413
- while ( index < text . length && ( index = text . indexOf ( id , index ) ) !== - 1 ) {
414
- if ( ! isIdChar ( text . charAt ( index - 1 ) ) && ! isIdChar ( text . charAt ( index + id . length ) ) ) {
415
- const isExportDeclaration = index === item . pos || index === item . pos + 1 ; // off-by-one from `stripQuotes`
416
- if ( ! isExportDeclaration ) {
417
- // @ts -expect-error ts.getTokenAtPosition is internal fn
418
- const symbol = typeChecker . getSymbolAtLocation ( ts . getTokenAtPosition ( sourceFile , index ) ) ;
419
- if ( symbol ) {
420
- const isInExportedType = referencedSymbolsInExportedTypes . has ( symbol ) ;
421
- if ( item . symbol === symbol ) {
422
- item . refs = [ 1 , isInExportedType ] ;
423
- if ( isInExportedType || isType ( item ) ) break ;
424
- }
425
- // @ts -expect-error Keep it cheap
426
- const declaration = symbol . declarations ?. [ 0 ] ;
427
- if ( declaration ) {
428
- if ( item . symbol === declaration . name ?. flowNode ?. node ?. symbol ) {
429
- item . refs = [ 1 , isInExportedType ] ;
430
- break ;
431
- }
432
- if ( ts . isImportSpecifier ( declaration ) && symbols . has ( symbol ) ) {
433
- // re-exported symbol is referenced
434
- item . refs = [ 1 , isInExportedType ] ;
435
- break ;
436
- }
437
- }
438
- symbols . add ( symbol ) ;
439
- }
440
- }
441
- }
442
- index += id . length ;
443
- }
444
- } ;
445
-
446
397
const isSetRefs = ignoreExportsUsedInFile ;
447
398
for ( const item of exports . values ( ) ) {
448
399
if ( isSetRefs === true || ( typeof isSetRefs === 'object' && item . type !== 'unknown' && ! ! isSetRefs [ item . type ] ) ) {
449
- setRefs ( item ) ;
400
+ item . refs = findInternalReferences ( item , sourceFile , typeChecker , referencedSymbolsInExportedTypes ) ;
450
401
}
451
402
for ( const member of item . members ) {
452
- setRefs ( member ) ;
403
+ member . refs = findInternalReferences ( member , sourceFile , typeChecker , referencedSymbolsInExportedTypes ) ;
453
404
member . symbol = undefined ;
454
405
}
455
406
item . symbol = undefined ;
0 commit comments