Skip to content

Commit

Permalink
Print trailing comma after a single TS generic in arrow fns (#14113)
Browse files Browse the repository at this point in the history
  • Loading branch information
ozanhonamlioglu committed Jan 10, 2022
1 parent a6d77d0 commit 1c32b67
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 6 deletions.
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;
}

0 comments on commit 1c32b67

Please sign in to comment.