Skip to content
This repository was archived by the owner on Jun 11, 2020. It is now read-only.

Commit 0051a77

Browse files
committed
Add dependencies for import types
1 parent dd69e3b commit 0051a77

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/lib/module-info.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,35 +265,43 @@ function findReferencedFiles(src: ts.SourceFile, packageName: string, subDirecto
265265
* All strings referenced in `import` statements.
266266
* Does *not* include <reference> directives.
267267
*/
268-
function* imports({ statements }: ts.SourceFile | ts.ModuleBlock): Iterable<string> {
269-
for (const node of statements) {
268+
function imports(sourceFile: ts.SourceFile): Iterable<string> {
269+
const result: string[] = [];
270+
ts.forEachChild(sourceFile, traverse);
271+
return result;
272+
273+
function traverse(node: ts.Node) {
270274
switch (node.kind) {
271275
case ts.SyntaxKind.ImportDeclaration:
272276
case ts.SyntaxKind.ExportDeclaration: {
273277
const { moduleSpecifier } = node as ts.ImportDeclaration | ts.ExportDeclaration;
274278
if (moduleSpecifier && moduleSpecifier.kind === ts.SyntaxKind.StringLiteral) {
275-
yield (moduleSpecifier as ts.StringLiteral).text;
279+
result.push((moduleSpecifier as ts.StringLiteral).text);
276280
}
277281
break;
278282
}
279283

280284
case ts.SyntaxKind.ImportEqualsDeclaration: {
281285
const { moduleReference } = node as ts.ImportEqualsDeclaration;
282286
if (moduleReference.kind === ts.SyntaxKind.ExternalModuleReference) {
283-
yield parseRequire(moduleReference);
287+
result.push(parseRequire(moduleReference));
284288
}
285289
break;
286290
}
287291

288-
case ts.SyntaxKind.ModuleDeclaration: {
289-
const { name, body } = node as ts.ModuleDeclaration;
290-
if (name.kind === ts.SyntaxKind.StringLiteral && body) {
291-
yield* imports(body as ts.ModuleBlock);
292+
case ts.SyntaxKind.ImportType: {
293+
const { argument } = node as ts.ImportTypeNode;
294+
if (argument.kind === ts.SyntaxKind.LiteralType) {
295+
const { literal } = argument as ts.LiteralTypeNode;
296+
if (literal.kind === ts.SyntaxKind.StringLiteral) {
297+
result.push(literal.text);
298+
}
292299
}
293300
break;
294301
}
295302

296303
default:
304+
ts.forEachChild(node, traverse);
297305
}
298306
}
299307
}

0 commit comments

Comments
 (0)