From f89f56650b4bc8155dcc9439af5f43d2a9af9721 Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Mon, 20 Apr 2020 18:34:34 -0700 Subject: [PATCH 1/3] Add dependencies for types imports --- .../definitions-parser/src/lib/module-info.ts | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/definitions-parser/src/lib/module-info.ts b/packages/definitions-parser/src/lib/module-info.ts index 6e9b5f1abf..f2170c705c 100644 --- a/packages/definitions-parser/src/lib/module-info.ts +++ b/packages/definitions-parser/src/lib/module-info.ts @@ -275,14 +275,20 @@ function findReferencedFiles(src: ts.SourceFile, packageName: string, subDirecto * All strings referenced in `import` statements. * Does *not* include directives. */ -function* imports({ statements }: ts.SourceFile | ts.ModuleBlock): Iterable { +function imports({ statements }: ts.SourceFile): Iterable { + const result: string[] = []; for (const node of statements) { + recur(node); + } + return result; + + function recur(node: ts.Node) { switch (node.kind) { case ts.SyntaxKind.ImportDeclaration: case ts.SyntaxKind.ExportDeclaration: { const { moduleSpecifier } = node as ts.ImportDeclaration | ts.ExportDeclaration; if (moduleSpecifier && moduleSpecifier.kind === ts.SyntaxKind.StringLiteral) { - yield (moduleSpecifier as ts.StringLiteral).text; + result.push((moduleSpecifier as ts.StringLiteral).text); } break; } @@ -290,20 +296,24 @@ function* imports({ statements }: ts.SourceFile | ts.ModuleBlock): Iterable Date: Thu, 27 Aug 2020 11:12:41 -0700 Subject: [PATCH 2/3] Add tests --- .../definitions-parser/test/module-info.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/definitions-parser/test/module-info.test.ts b/packages/definitions-parser/test/module-info.test.ts index 62797f9276..c7e79d4144 100644 --- a/packages/definitions-parser/test/module-info.test.ts +++ b/packages/definitions-parser/test/module-info.test.ts @@ -62,6 +62,19 @@ testo({ expect(Array.from(types.keys())).toEqual(["merges.d.ts"]); expect(Array.from(tests.keys())).toEqual(["globby-tests.ts", "test/other-tests.ts"]); }, + allReferencedFilesIncludesTypesImports() { + const pkg = new Dir(undefined); + pkg.set( + "index.d.ts", + `type T = import("./types"); +` + ); + pkg.set("types.d.ts", ""); + const memFS = new InMemoryFS(pkg, "types/mock"); + const { types, tests } = allReferencedFiles(["index.d.ts"], memFS, "mock", "types/mock"); + expect(Array.from(types.keys())).toEqual(["index.d.ts", "types.d.ts"]); + expect(Array.from(tests.keys())).toEqual([]); + }, getModuleInfoWorksWithOtherFiles() { const { types } = getBoringReferences(); // written as if it were from OTHER_FILES.txt From a70935557fd3daf3ee3258fb57703cbe0545c268 Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Thu, 24 Sep 2020 12:45:01 -0700 Subject: [PATCH 3/3] =?UTF-8?q?Improve=20style=20=F0=9F=8E=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> --- packages/definitions-parser/src/lib/module-info.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/definitions-parser/src/lib/module-info.ts b/packages/definitions-parser/src/lib/module-info.ts index f2170c705c..840178590f 100644 --- a/packages/definitions-parser/src/lib/module-info.ts +++ b/packages/definitions-parser/src/lib/module-info.ts @@ -303,11 +303,8 @@ function imports({ statements }: ts.SourceFile): Iterable { case ts.SyntaxKind.ImportType: { const { argument } = node as ts.ImportTypeNode; - if (argument.kind === ts.SyntaxKind.LiteralType) { - const { literal } = argument as ts.LiteralTypeNode; - if (literal.kind === ts.SyntaxKind.StringLiteral) { - result.push(literal.text); - } + if (ts.isLiteralTypeNode(argument) && ts.isStringLiteral(argument.literal)) { + result.push(argument.literal.text); } break; }