Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions src/services/importTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ namespace ts.FindAllReferences {

/** Calls `action` for each import, re-export, or require() in a file. */
function forEachImport(sourceFile: SourceFile, action: (importStatement: ImporterOrCallExpression, imported: StringLiteral) => void): void {
if (sourceFile.externalModuleIndicator) {
if (sourceFile.externalModuleIndicator || sourceFile.imports !== undefined) {
for (const moduleSpecifier of sourceFile.imports) {
action(importerFromModuleSpecifier(moduleSpecifier), moduleSpecifier);
}
Expand Down Expand Up @@ -358,27 +358,21 @@ namespace ts.FindAllReferences {
}
}
});

if (sourceFile.flags & NodeFlags.JavaScriptFile) {
// Find all 'require()' calls.
sourceFile.forEachChild(function recur(node: Node): void {
if (isRequireCall(node, /*checkArgumentIsStringLiteral*/ true)) {
action(node, node.arguments[0] as StringLiteral);
} else {
node.forEachChild(recur);
}
});
}
}
}

function importerFromModuleSpecifier(moduleSpecifier: StringLiteral): Importer {
function importerFromModuleSpecifier(moduleSpecifier: StringLiteral): ImporterOrCallExpression {
const decl = moduleSpecifier.parent;
if (decl.kind === SyntaxKind.ImportDeclaration || decl.kind === SyntaxKind.ExportDeclaration) {
return decl as ImportDeclaration | ExportDeclaration;
switch (decl.kind) {
case SyntaxKind.CallExpression:
case SyntaxKind.ImportDeclaration:
case SyntaxKind.ExportDeclaration:
return decl as ImportDeclaration | ExportDeclaration | CallExpression;
case SyntaxKind.ExternalModuleReference:
return (decl as ExternalModuleReference).parent;
default:
Debug.assert(false);
}
Debug.assert(decl.kind === SyntaxKind.ExternalModuleReference);
return (decl as ExternalModuleReference).parent;
}

export interface ImportedSymbol {
Expand Down