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

Support TS 4.7 instantiation expression #12898

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
4 changes: 3 additions & 1 deletion src/language-js/print/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function printTypescript(path, options, print) {

return parts;
case "TSTypeQuery":
return ["typeof ", print("exprName")];
return ["typeof ", print("exprName"), print("typeParameters")];
case "TSIndexSignature": {
const parent = path.getParentNode();

Expand Down Expand Up @@ -520,6 +520,8 @@ function printTypescript(path, options, print) {
return ["?", print("typeAnnotation")];
case "TSJSDocNonNullableType":
return ["!", print("typeAnnotation")];
case "TSInstantiationExpression":
return [print("expression"), print("typeParameters")];
default:
/* istanbul ignore next */
throw new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,34 @@ type X9<U, T> = T extends (infer U extends number ? U : T) ? U : T;
================================================================================
`;

exports[`ts-4.7-instantiation-expression.ts format 1`] = `
====================================options=====================================
parsers: ["babel-ts"]
printWidth: 80
| printWidth
=====================================input======================================
// basic
const foo = bar<T>;

// typeof
let x: typeof y.z<w>;

// new
new A<T>;

=====================================output=====================================
// basic
const foo = bar<T>;

// typeof
let x: typeof y.z<w>;

// new
new A<T>();

================================================================================
`;

exports[`tuple-labeled-ts.ts format 1`] = `
====================================options=====================================
parsers: ["babel-ts"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// basic
const foo = bar<T>;

// typeof
let x: typeof y.z<w>;

// new
new A<T>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`binary-expr.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
| printWidth
=====================================input======================================
new A < B >
C

=====================================output=====================================
new A() < B > C;

================================================================================
`;

exports[`inferface-asi.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
| printWidth
=====================================input======================================
interface Example {
(a: number): typeof a

<T>(): void
};

=====================================output=====================================
interface Example {
(a: number): typeof a;

<T>(): void;
}

================================================================================
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
new A < B >
C
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface Example {
(a: number): typeof a

<T>(): void
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run_spec(__dirname, ["typescript"]);