@@ -330,7 +330,7 @@ namespace ts.FindAllReferences {
330
330
331
331
/** Calls `action` for each import, re-export, or require() in a file. */
332
332
function forEachImport ( sourceFile : SourceFile , action : ( importStatement : ImporterOrCallExpression , imported : StringLiteral ) => void ) : void {
333
- if ( sourceFile . externalModuleIndicator ) {
333
+ if ( sourceFile . externalModuleIndicator || sourceFile . imports !== undefined ) {
334
334
for ( const moduleSpecifier of sourceFile . imports ) {
335
335
action ( importerFromModuleSpecifier ( moduleSpecifier ) , moduleSpecifier ) ;
336
336
}
@@ -358,27 +358,21 @@ namespace ts.FindAllReferences {
358
358
}
359
359
}
360
360
} ) ;
361
-
362
- if ( sourceFile . flags & NodeFlags . JavaScriptFile ) {
363
- // Find all 'require()' calls.
364
- sourceFile . forEachChild ( function recur ( node : Node ) : void {
365
- if ( isRequireCall ( node , /*checkArgumentIsStringLiteral*/ true ) ) {
366
- action ( node , node . arguments [ 0 ] as StringLiteral ) ;
367
- } else {
368
- node . forEachChild ( recur ) ;
369
- }
370
- } ) ;
371
- }
372
361
}
373
362
}
374
363
375
- function importerFromModuleSpecifier ( moduleSpecifier : StringLiteral ) : Importer {
364
+ function importerFromModuleSpecifier ( moduleSpecifier : StringLiteral ) : ImporterOrCallExpression {
376
365
const decl = moduleSpecifier . parent ;
377
- if ( decl . kind === SyntaxKind . ImportDeclaration || decl . kind === SyntaxKind . ExportDeclaration ) {
378
- return decl as ImportDeclaration | ExportDeclaration ;
366
+ switch ( decl . kind ) {
367
+ case SyntaxKind . CallExpression :
368
+ case SyntaxKind . ImportDeclaration :
369
+ case SyntaxKind . ExportDeclaration :
370
+ return decl as ImportDeclaration | ExportDeclaration | CallExpression ;
371
+ case SyntaxKind . ExternalModuleReference :
372
+ return ( decl as ExternalModuleReference ) . parent ;
373
+ default :
374
+ Debug . assert ( false ) ;
379
375
}
380
- Debug . assert ( decl . kind === SyntaxKind . ExternalModuleReference ) ;
381
- return ( decl as ExternalModuleReference ) . parent ;
382
376
}
383
377
384
378
export interface ImportedSymbol {
0 commit comments