Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(typescript): no invalid output for ImportType in TypeReference #4939

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -58,7 +58,7 @@
"semver": "5.4.1",
"string-width": "2.1.1",
"typescript": "3.0.0-dev.20180626",
"typescript-eslint-parser": "17.0.0",
"typescript-eslint-parser": "ikatyang/typescript-eslint-parser#504a576277b744ba31f293db5453bca9fe0e2cb4",
"unicode-regex": "1.0.1",
"unified": "6.1.6",
"yaml": "ikatyang/yaml#a765c1ee16d6b8a5e715564645f2b85f7e04828b",
Expand Down
4 changes: 2 additions & 2 deletions src/language-js/printer-estree.js
Expand Up @@ -2923,11 +2923,11 @@ function printPathNoParens(path, options, print, args) {
return concat([path.call(print, "expression"), "!"]);
case "TSThisType":
return "this";
case "TSLastTypeNode": // TSImportType
case "TSImportType":
return concat([
!n.isTypeOf ? "" : "typeof ",
"import(",
path.call(print, "argument"),
path.call(print, "parameter"),
")",
!n.qualifier ? "" : concat([".", path.call(print, "qualifier")]),
printTypeParameters(path, options, print, "typeParameters")
Expand Down
8 changes: 8 additions & 0 deletions tests/typescript_import_type/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -14,6 +14,8 @@ export let shim: typeof import("./foo2") = {
export interface Foo {
bar: import('immutable').Map<string, int>;
}

type X = A<import("B").C<any>>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ref: https://github.com/Microsoft/TypeScript/pull/22592

Expand All @@ -29,6 +31,8 @@ export interface Foo {
bar: import("immutable").Map<string, int>;
}

type X = A<import("B").C<any>>;

`;

exports[`import-type.ts - typescript-verify 2`] = `
Expand All @@ -45,6 +49,8 @@ export let shim: typeof import("./foo2") = {
export interface Foo {
bar: import('immutable').Map<string, int>;
}

type X = A<import("B").C<any>>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ref: https://github.com/Microsoft/TypeScript/pull/22592

Expand All @@ -60,4 +66,6 @@ export interface Foo {
bar: import('immutable').Map<string, int>;
}

type X = A<import('B').C<any>>;

`;
2 changes: 2 additions & 0 deletions tests/typescript_import_type/import-type.ts
Expand Up @@ -11,3 +11,5 @@ export let shim: typeof import("./foo2") = {
export interface Foo {
bar: import('immutable').Map<string, int>;
}

type X = A<import("B").C<any>>;
6 changes: 3 additions & 3 deletions yarn.lock
Expand Up @@ -5680,9 +5680,9 @@ typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

typescript-eslint-parser@17.0.0:
version "17.0.0"
resolved "https://registry.yarnpkg.com/typescript-eslint-parser/-/typescript-eslint-parser-17.0.0.tgz#0e2b5c0d15f2e2cfdf43dd024c96b10d016bef26"
typescript-eslint-parser@ikatyang/typescript-eslint-parser#504a576277b744ba31f293db5453bca9fe0e2cb4:
version "17.0.1"
resolved "https://codeload.github.com/ikatyang/typescript-eslint-parser/tar.gz/504a576277b744ba31f293db5453bca9fe0e2cb4"
dependencies:
lodash.unescape "4.0.1"
semver "5.5.0"
Expand Down