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 all 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
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -57,8 +57,8 @@
"resolve": "1.5.0",
"semver": "5.4.1",
"string-width": "2.1.1",
"typescript": "3.0.0-dev.20180626",
"typescript-eslint-parser": "17.0.0",
"typescript": "3.0.1",
"typescript-eslint-parser": "18.0.0",
"unicode-regex": "1.0.1",
"unified": "6.1.6",
"yaml": "ikatyang/yaml#a765c1ee16d6b8a5e715564645f2b85f7e04828b",
Expand Down Expand Up @@ -117,7 +117,7 @@
"perf-benchmark": "yarn && yarn build && cross-env NODE_ENV=production node ./dist/bin-prettier.js --debug-benchmark --loglevel debug ${PERF_FILE:-./index.js} > /dev/null",
"lint": "cross-env EFF_NO_LINK_RULES=true eslint . --format node_modules/eslint-friendly-formatter",
"lint-docs": "prettylint {.,docs,website,website/blog}/*.md",
"build": "node ./scripts/build/build.js",
"build": "node --max-old-space-size=2048 ./scripts/build/build.js",
"build-docs": "node ./scripts/build-docs.js",
"check-deps": "node ./scripts/check-deps.js"
}
Expand Down
4 changes: 3 additions & 1 deletion scripts/build-docs.js
Expand Up @@ -5,6 +5,8 @@
const path = require("path");
const shell = require("shelljs");

shell.config.fatal = true;

const rootDir = path.join(__dirname, "..");
const docs = path.join(rootDir, "website/static/lib");

Expand All @@ -22,7 +24,7 @@ if (isPullRequest) {
const pkg = require("../package.json");
pkg.version = `999.999.999-pr.${process.env.REVIEW_ID}`;
pipe(JSON.stringify(pkg, null, 2)).to("package.json");
shell.exec("node scripts/build/build.js");
shell.exec("yarn build");
}
shell.exec(`cp ${prettierPath}/standalone.js ${docs}/`);
shell.exec(`cp ${prettierPath}/parser-*.js ${docs}/`);
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>>;
12 changes: 6 additions & 6 deletions yarn.lock
Expand Up @@ -5680,16 +5680,16 @@ 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@18.0.0:
version "18.0.0"
resolved "https://registry.yarnpkg.com/typescript-eslint-parser/-/typescript-eslint-parser-18.0.0.tgz#3e5055a44980d69e4154350fc5d8b1ab4e2332a8"
dependencies:
lodash.unescape "4.0.1"
semver "5.5.0"

typescript@3.0.0-dev.20180626:
version "3.0.0-dev.20180626"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.0-dev.20180626.tgz#fb6be91cfc8e8757d551e83af208d0083be61499"
typescript@3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.1.tgz#43738f29585d3a87575520a4b93ab6026ef11fdb"

ua-parser-js@^0.7.9:
version "0.7.17"
Expand Down