From 61d35dd6364d6614616d153e57e316ed3c51973b Mon Sep 17 00:00:00 2001 From: Lynn Smeria Date: Mon, 11 Jun 2018 03:29:10 +0200 Subject: [PATCH] fix(typescript): preserve type parameters of import-types (#4656) (#4662) --- src/language-js/printer-estree.js | 3 ++- .../__snapshots__/jsfmt.spec.js.snap | 16 ++++++++++++++++ tests/typescript_import_type/import-type.ts | 4 ++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index 503b4057..0a851e55 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -2940,7 +2940,8 @@ function printPathNoParens(path, options, print, args) { "import(", path.call(print, "argument"), ")", - !n.qualifier ? "" : concat([".", path.call(print, "qualifier")]) + !n.qualifier ? "" : concat([".", path.call(print, "qualifier")]), + printTypeParameters(path, options, print, "typeParameters") ]); case "TSLiteralType": return path.call(print, "literal"); diff --git a/tests/typescript_import_type/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_import_type/__snapshots__/jsfmt.spec.js.snap index 387f8254..1c1c35c5 100644 --- a/tests/typescript_import_type/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_import_type/__snapshots__/jsfmt.spec.js.snap @@ -10,6 +10,10 @@ export let y: import("./foo2").Bar.I = { a: "", b: 0 }; export let shim: typeof import("./foo2") = { Bar: Bar2 }; + +export interface Foo { + bar: import('immutable').Map; +} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ref: https://github.com/Microsoft/TypeScript/pull/22592 @@ -21,6 +25,10 @@ export let shim: typeof import("./foo2") = { Bar: Bar2 }; +export interface Foo { + bar: import("immutable").Map; +} + `; exports[`import-type.ts 2`] = ` @@ -33,6 +41,10 @@ export let y: import("./foo2").Bar.I = { a: "", b: 0 }; export let shim: typeof import("./foo2") = { Bar: Bar2 }; + +export interface Foo { + bar: import('immutable').Map; +} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ref: https://github.com/Microsoft/TypeScript/pull/22592 @@ -44,4 +56,8 @@ export let shim: typeof import('./foo2') = { Bar: Bar2 }; +export interface Foo { + bar: import('immutable').Map; +} + `; diff --git a/tests/typescript_import_type/import-type.ts b/tests/typescript_import_type/import-type.ts index 3d7924e2..d3c6db51 100644 --- a/tests/typescript_import_type/import-type.ts +++ b/tests/typescript_import_type/import-type.ts @@ -7,3 +7,7 @@ export let y: import("./foo2").Bar.I = { a: "", b: 0 }; export let shim: typeof import("./foo2") = { Bar: Bar2 }; + +export interface Foo { + bar: import('immutable').Map; +}