From 1d885b392e5ade901ca3c5e9fc62078a67a390f6 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 5 Jun 2018 12:35:28 -0700 Subject: [PATCH] Visit the children of an import type/require call/dynamic import when looking for those (#24663) (#24670) --- src/compiler/program.ts | 8 +++---- .../importUsedInGenericImportResolves.js | 17 ++++++++++++++ .../importUsedInGenericImportResolves.symbols | 21 +++++++++++++++++ .../importUsedInGenericImportResolves.types | 23 +++++++++++++++++++ .../importUsedInGenericImportResolves.ts | 10 ++++++++ 5 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 tests/baselines/reference/importUsedInGenericImportResolves.js create mode 100644 tests/baselines/reference/importUsedInGenericImportResolves.symbols create mode 100644 tests/baselines/reference/importUsedInGenericImportResolves.types create mode 100644 tests/cases/compiler/importUsedInGenericImportResolves.ts diff --git a/src/compiler/program.ts b/src/compiler/program.ts index c453080f3bf..1e0ebf1d552 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1802,11 +1802,9 @@ namespace ts { else if (isLiteralImportTypeNode(node)) { imports = append(imports, node.argument.literal); } - else { - collectDynamicImportOrRequireCallsForEachChild(node); - if (hasJSDocNodes(node)) { - forEach(node.jsDoc, collectDynamicImportOrRequireCallsForEachChild); - } + collectDynamicImportOrRequireCallsForEachChild(node); + if (hasJSDocNodes(node)) { + forEach(node.jsDoc, collectDynamicImportOrRequireCallsForEachChild); } } diff --git a/tests/baselines/reference/importUsedInGenericImportResolves.js b/tests/baselines/reference/importUsedInGenericImportResolves.js new file mode 100644 index 00000000000..05d64b1c19a --- /dev/null +++ b/tests/baselines/reference/importUsedInGenericImportResolves.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/importUsedInGenericImportResolves.ts] //// + +//// [test1.d.ts] +export interface T

{ + a: P; +} + +//// [test2.d.ts] +export declare const theme: { a: string } + +//// [test3.ts] +export const a: import("./test1").T = null as any; + +//// [test3.js] +"use strict"; +exports.__esModule = true; +exports.a = null; diff --git a/tests/baselines/reference/importUsedInGenericImportResolves.symbols b/tests/baselines/reference/importUsedInGenericImportResolves.symbols new file mode 100644 index 00000000000..6c240d19137 --- /dev/null +++ b/tests/baselines/reference/importUsedInGenericImportResolves.symbols @@ -0,0 +1,21 @@ +=== tests/cases/compiler/test1.d.ts === +export interface T

{ +>T : Symbol(T, Decl(test1.d.ts, 0, 0)) +>P : Symbol(P, Decl(test1.d.ts, 0, 19)) + + a: P; +>a : Symbol(T.a, Decl(test1.d.ts, 0, 23)) +>P : Symbol(P, Decl(test1.d.ts, 0, 19)) +} + +=== tests/cases/compiler/test2.d.ts === +export declare const theme: { a: string } +>theme : Symbol(theme, Decl(test2.d.ts, 0, 20)) +>a : Symbol(a, Decl(test2.d.ts, 0, 29)) + +=== tests/cases/compiler/test3.ts === +export const a: import("./test1").T = null as any; +>a : Symbol(a, Decl(test3.ts, 0, 12)) +>T : Symbol(T, Decl(test1.d.ts, 0, 0)) +>theme : Symbol(theme, Decl(test2.d.ts, 0, 20)) + diff --git a/tests/baselines/reference/importUsedInGenericImportResolves.types b/tests/baselines/reference/importUsedInGenericImportResolves.types new file mode 100644 index 00000000000..c101b0d73ef --- /dev/null +++ b/tests/baselines/reference/importUsedInGenericImportResolves.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/test1.d.ts === +export interface T

{ +>T : T

+>P : P + + a: P; +>a : P +>P : P +} + +=== tests/cases/compiler/test2.d.ts === +export declare const theme: { a: string } +>theme : { a: string; } +>a : string + +=== tests/cases/compiler/test3.ts === +export const a: import("./test1").T = null as any; +>a : import("tests/cases/compiler/test1").T<{ a: string; }> +>T : import("tests/cases/compiler/test1").T

+>theme : any +>null as any : any +>null : null + diff --git a/tests/cases/compiler/importUsedInGenericImportResolves.ts b/tests/cases/compiler/importUsedInGenericImportResolves.ts new file mode 100644 index 00000000000..88c57804c98 --- /dev/null +++ b/tests/cases/compiler/importUsedInGenericImportResolves.ts @@ -0,0 +1,10 @@ +// @filename: test1.d.ts +export interface T

{ + a: P; +} + +// @filename: test2.d.ts +export declare const theme: { a: string } + +// @filename: test3.ts +export const a: import("./test1").T = null as any; \ No newline at end of file