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

Print trailing comma after a single TS generic in arrow fns #14113

Merged
merged 5 commits into from Jan 10, 2022
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: 4 additions & 0 deletions packages/babel-generator/src/generators/typescript.ts
Expand Up @@ -12,9 +12,13 @@ export function TSTypeAnnotation(this: Printer, node: t.TSTypeAnnotation) {
export function TSTypeParameterInstantiation(
this: Printer,
node: t.TSTypeParameterInstantiation,
parent: t.Node,
): void {
this.token("<");
this.printList(node.params, node, {});
if (parent.type === "ArrowFunctionExpression" && node.params.length === 1) {
this.token(",");
}
this.token(">");
}

Expand Down
@@ -1 +1 @@
async <T>(a: T): T => a;
async <T,>(a: T): T => a;
@@ -0,0 +1,2 @@
// Verify typescript doesn't change anything inside type parameter declaration
const foo = <T,>(a: T): T => a;
@@ -0,0 +1,3 @@
{
"plugins": ["jsx", "typescript"]
}
@@ -0,0 +1,2 @@
// Verify typescript doesn't change anything inside type parameter declaration
const foo = <T,>(a: T): T => a;
@@ -1,2 +1,2 @@
// Same as `generic`. Verify that JSX doesn't change things.
<T>(a: T): T => a;
<T,>(a: T): T => a;
@@ -1 +1 @@
<T>(a: T): T => a;
<T,>(a: T): T => a;
@@ -1,3 +1,3 @@
<T>() => 1;
<T,>() => 1;

<T>(x) => 1;
<T,>(x) => 1;
Expand Up @@ -4,6 +4,6 @@ function a() {
}

function d() {
let e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : <T>() => {};
let e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : <T,>() => {};
let T;
}