Skip to content

Commit

Permalink
fix: support dynamic type imports in getReferencedSourceFiles() (#1436)
Browse files Browse the repository at this point in the history
  • Loading branch information
lo1tuma committed Sep 6, 2023
1 parent 382f0c8 commit 7207de1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1281,12 +1281,14 @@ function myFunction(param: MyClass) {
const file2 = project.createSourceFile("/file2.ts", `import {MyInterface} from "./MyInterface";`);
const file3 = project.createSourceFile("/file3.ts", `export * from "./MyInterface";`);
const file4 = project.createSourceFile("/file4.ts", `const t = import("./MyInterface");`);
const file5 = project.createSourceFile("/file5.ts", `declare const t: import("./MyInterface").MyInterface;`);

expectResult(sourceFile, []);
expectResult(file1, [sourceFile]);
expectResult(file2, [sourceFile]);
expectResult(file3, [sourceFile]);
expectResult(file4, [sourceFile]);
expectResult(file5, [sourceFile]);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ export class SourceFileReferenceContainer {
return parent.getModuleSpecifierSourceFile();
else if (grandParent != null && Node.isImportEqualsDeclaration(grandParent))
return grandParent.getExternalModuleReferenceSourceFile();
else if (Node.isCallExpression(parent)) {
else if (grandParent != null && Node.isImportTypeNode(grandParent)) {
const importTypeSymbol = grandParent.getSymbol()
if (importTypeSymbol != null)
return ModuleUtils.getReferencedSourceFileFromSymbol(importTypeSymbol);
} else if (Node.isCallExpression(parent)) {
const literalSymbol = literal.getSymbol();
if (literalSymbol != null)
return ModuleUtils.getReferencedSourceFileFromSymbol(literalSymbol);
Expand Down

0 comments on commit 7207de1

Please sign in to comment.