Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support dynamic type imports in getReferencedSourceFiles() #1436

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
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
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