Skip to content

Commit

Permalink
Support TSNamedTupleMember
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Aug 2, 2020
1 parent be37c4f commit f7d2b83
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/language-js/printer-estree.js
Expand Up @@ -2314,6 +2314,13 @@ function printPathNoParens(path, options, print, args) {

/* istanbul ignore next */
return "";
case "TSNamedTupleMember":
return concat([
path.call(print, "label"),
n.optional ? "?":"",
": ",
path.call(print, "elementType"),
]);
case "TSTupleType":
case "TupleTypeAnnotation": {
const typesField = n.type === "TSTupleType" ? "elementTypes" : "types";
Expand Down
57 changes: 57 additions & 0 deletions tests/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap
@@ -0,0 +1,57 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`tuple-labeled.ts format 1`] = `
====================================options=====================================
parsers: ["babel-ts"]
printWidth: 80
| printWidth
=====================================input======================================
// https://github.com/babel/babel/pull/11754
// TODO: move this file to \`test/typescript/tuple\`
type T = [x: A, y?: B, ...z: C];
type T = [A, y: B];
let x: [A: string, ...B: number[]]
type T = [foo: string, bar?: number];
type T = [x?: A, y: B];
type T = [x: A, ...B];
type T = [...B, x: A];
// Invalid label 1
type T = [x.y: A];
// Invalid label 2
type T = [x<y>: A];
=====================================output=====================================
// https://github.com/babel/babel/pull/11754
// TODO: move this file to \`test/typescript/tuple\`
type T = [x: A, y?: B, ...z: C];
type T = [A, y: B];
let x: [A: string, ...B: number[]];
type T = [foo: string, bar?: number];
type T = [x?: A, y: B];
type T = [x: A, ...B];
type T = [...B, x: A];
// Invalid label 1
type T = [x.y: A];
// Invalid label 2
type T = [x<y>: A];
================================================================================
`;
1 change: 1 addition & 0 deletions tests/misc/typescript-babel-only/jsfmt.spec.js
@@ -0,0 +1 @@
run_spec(__dirname, ["babel-ts"]);
22 changes: 22 additions & 0 deletions tests/misc/typescript-babel-only/tuple-labeled.ts
@@ -0,0 +1,22 @@
// https://github.com/babel/babel/pull/11754
// TODO: move this file to `test/typescript/tuple`

type T = [x: A, y?: B, ...z: C];

type T = [A, y: B];

let x: [A: string, ...B: number[]]

type T = [foo: string, bar?: number];

type T = [x?: A, y: B];

type T = [x: A, ...B];

type T = [...B, x: A];

// Invalid label 1
type T = [x.y: A];

// Invalid label 2
type T = [x<y>: A];

0 comments on commit f7d2b83

Please sign in to comment.