diff --git a/packages/babel-generator/src/generators/typescript.ts b/packages/babel-generator/src/generators/typescript.ts index f78bed5123ab..594fe26ba0ac 100644 --- a/packages/babel-generator/src/generators/typescript.ts +++ b/packages/babel-generator/src/generators/typescript.ts @@ -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(">"); } diff --git a/packages/babel-generator/test/fixtures/typescript/arrow-function-async-generic/output.js b/packages/babel-generator/test/fixtures/typescript/arrow-function-async-generic/output.js index c2b1123797f6..f0fe3c318301 100644 --- a/packages/babel-generator/test/fixtures/typescript/arrow-function-async-generic/output.js +++ b/packages/babel-generator/test/fixtures/typescript/arrow-function-async-generic/output.js @@ -1 +1 @@ -async (a: T): T => a; \ No newline at end of file +async (a: T): T => a; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/typescript/arrow-function-generic-tsx-trailing-comma/input.js b/packages/babel-generator/test/fixtures/typescript/arrow-function-generic-tsx-trailing-comma/input.js new file mode 100644 index 000000000000..8dfcb38201a3 --- /dev/null +++ b/packages/babel-generator/test/fixtures/typescript/arrow-function-generic-tsx-trailing-comma/input.js @@ -0,0 +1,2 @@ +// Verify typescript doesn't change anything inside type parameter declaration +const foo = (a: T): T => a; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/typescript/arrow-function-generic-tsx-trailing-comma/options.json b/packages/babel-generator/test/fixtures/typescript/arrow-function-generic-tsx-trailing-comma/options.json new file mode 100644 index 000000000000..b2578f32c45a --- /dev/null +++ b/packages/babel-generator/test/fixtures/typescript/arrow-function-generic-tsx-trailing-comma/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["jsx", "typescript"] +} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/typescript/arrow-function-generic-tsx-trailing-comma/output.js b/packages/babel-generator/test/fixtures/typescript/arrow-function-generic-tsx-trailing-comma/output.js new file mode 100644 index 000000000000..8dfcb38201a3 --- /dev/null +++ b/packages/babel-generator/test/fixtures/typescript/arrow-function-generic-tsx-trailing-comma/output.js @@ -0,0 +1,2 @@ +// Verify typescript doesn't change anything inside type parameter declaration +const foo = (a: T): T => a; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/typescript/arrow-function-generic-tsx/output.js b/packages/babel-generator/test/fixtures/typescript/arrow-function-generic-tsx/output.js index fc243c0e52bd..5badd4ab2367 100644 --- a/packages/babel-generator/test/fixtures/typescript/arrow-function-generic-tsx/output.js +++ b/packages/babel-generator/test/fixtures/typescript/arrow-function-generic-tsx/output.js @@ -1,2 +1,2 @@ // Same as `generic`. Verify that JSX doesn't change things. -(a: T): T => a; \ No newline at end of file +(a: T): T => a; \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/typescript/arrow-function-generic/output.js b/packages/babel-generator/test/fixtures/typescript/arrow-function-generic/output.js index 965d8d668f33..64cd30270e36 100644 --- a/packages/babel-generator/test/fixtures/typescript/arrow-function-generic/output.js +++ b/packages/babel-generator/test/fixtures/typescript/arrow-function-generic/output.js @@ -1 +1 @@ -(a: T): T => a; \ No newline at end of file +(a: T): T => a; \ No newline at end of file diff --git a/packages/babel-plugin-syntax-typescript/test/fixtures/disallow-jsx-ambiguity/type-parameter-unambiguous/output.js b/packages/babel-plugin-syntax-typescript/test/fixtures/disallow-jsx-ambiguity/type-parameter-unambiguous/output.js index 26d3834d427d..595d787ef930 100644 --- a/packages/babel-plugin-syntax-typescript/test/fixtures/disallow-jsx-ambiguity/type-parameter-unambiguous/output.js +++ b/packages/babel-plugin-syntax-typescript/test/fixtures/disallow-jsx-ambiguity/type-parameter-unambiguous/output.js @@ -1,3 +1,3 @@ -() => 1; +() => 1; -(x) => 1; +(x) => 1; diff --git a/packages/babel-plugin-transform-parameters/test/fixtures/regression/11344-typescript/output.js b/packages/babel-plugin-transform-parameters/test/fixtures/regression/11344-typescript/output.js index d4d757d31d0d..55ac26c7df53 100644 --- a/packages/babel-plugin-transform-parameters/test/fixtures/regression/11344-typescript/output.js +++ b/packages/babel-plugin-transform-parameters/test/fixtures/regression/11344-typescript/output.js @@ -4,6 +4,6 @@ function a() { } function d() { - let e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : () => {}; + let e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : () => {}; let T; }