From 76a5f3c7b61e37bcb96107b50429201053696f6f Mon Sep 17 00:00:00 2001 From: Ika Date: Tue, 8 May 2018 12:35:12 +0800 Subject: [PATCH] fix(typescript): add missing `qualifier` and `typeof` in TSImportType (#4438) --- src/language-js/printer-estree.js | 8 +++++++- .../__snapshots__/jsfmt.spec.js.snap | 8 ++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index 1c16f678..9706ebec 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -2881,7 +2881,13 @@ function printPathNoParens(path, options, print, args) { case "TSThisType": return "this"; case "TSLastTypeNode": // TSImportType - return concat(["import(", path.call(print, "argument"), ")"]); + return concat([ + !n.isTypeOf ? "" : "typeof ", + "import(", + path.call(print, "argument"), + ")", + !n.qualifier ? "" : concat([".", path.call(print, "qualifier")]) + ]); case "TSLiteralType": return path.call(print, "literal"); case "TSIndexedAccessType": diff --git a/tests/typescript_import_type/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_import_type/__snapshots__/jsfmt.spec.js.snap index 709a5ec7..387f8254 100644 --- a/tests/typescript_import_type/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_import_type/__snapshots__/jsfmt.spec.js.snap @@ -15,9 +15,9 @@ export let shim: typeof import("./foo2") = { export const x: import("./foo") = { x: 0, y: 0 }; -export let y: import("./foo2") = { a: "", b: 0 }; +export let y: import("./foo2").Bar.I = { a: "", b: 0 }; -export let shim: import("./foo2") = { +export let shim: typeof import("./foo2") = { Bar: Bar2 }; @@ -38,9 +38,9 @@ export let shim: typeof import("./foo2") = { export const x: import('./foo') = { x: 0, y: 0 }; -export let y: import('./foo2') = { a: '', b: 0 }; +export let y: import('./foo2').Bar.I = { a: '', b: 0 }; -export let shim: import('./foo2') = { +export let shim: typeof import('./foo2') = { Bar: Bar2 };