Fix inconsistent union/intersection type format between TS and Flow (#14654)

This commit is contained in:
fisker Cheung authored and GitHub committed 2023-04-10 09:58:12 +08:00
1 parent 1e50206d28
commit 686320a88c
16 files changed
+654 -469

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
#### Fix formatting of union type with single type (#14654 by @fisker and @auvred)
<!-- prettier-ignore -->
```ts
// Input
type T =
| (
| {
value: number
}
| {
value: string
}
)
// Prettier stable
type T =
|
| {
value: number;
}
| {
value: string;
};
// Prettier main
type T =
| {
value: number;
}
| {
value: string;
};
```
+1
View File
@@ -26,6 +26,7 @@
"autoload",
"autoloaded",
"autoloading",
"auvred",
"Azzola",
"backticks",
"behaviour",
@@ -144,6 +144,13 @@ function postprocess(ast, options) {
}
break;
}
// In Flow parser, it doesn't generate union/intersection types for single type
case "TSUnionType":
case "TSIntersectionType":
if (node.types.length === 1) {
return node.types[0];
}
break;
}
});
+1
View File
@@ -43,6 +43,7 @@ const unstableTests = new Map(
["js/identifier/parentheses/let.js", (options) => options.semi === false],
"jsx/comments/in-attributes.js",
["js/ignore/semi/asi.js", (options) => options.semi === false],
"typescript/union/consistent-with-flow/single-type.ts",
].map((fixture) => {
const [file, isUnstable = () => true] = Array.isArray(fixture)
? fixture
@@ -1,202 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`intersection-parens.ts - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
semi: false
| printWidth
=====================================input======================================
type A = (number | string) & boolean;
type B = ((number | string)) & boolean;
type C = (((number | string))) & boolean;
type D = ((((number | string)))) & boolean;
let b1 : C;
let b2 : & C;
let b3 : (& C);
let b4 : & (C);
let b5 : (& (C));
let b6 : /*1*/ & C;
let b7 : /*1*/ & (C);
let b8 : /*1*/ (& C);
let b9 : (/*1*/ & C);
let b10: /*1*/ & /*2*/ C;
let b11: /*1*/ (& /*2*/ C);
let bb1: /*1*/ & /*2*/ C & D;
let bb2: /*1*/ & /*2*/ C & /*3*/ D;
let bb3: /*1*/ & /*2*/ C & /*3*/ D /*5*/;
type B2 = & C;
type B3 = (& C);
type B4 = & (C);
type B5 = (& (C));
type B6 = /*1*/ & C;
type B7 = /*1*/ & (C);
type B8 = /*1*/ (& C);
type B9 = (/*1*/ & C);
type B10 = /*1*/ & /*2*/ C;
type B11 = /*1*/ (& /*2*/ C);
type B12 = /*1*/ & ( (C));
type Bb1 = /*1*/ & /*2*/ C & D;
type Bb2 = /*1*/ & /*2*/ C & /*3*/ D;
type Bb3 = /*1*/ & /*2*/ C & /*3*/ D /*4*/;
type D1 = /*1*/ | a & b;
type D2 = /*1*/ | a & (b);
type D3 = /*1*/ | a & (| b);
type D4 = /*1*/ | (a & b);
type D5 = /*1*/ (| a & b);
type D6 /*0*/ = /*1*/ (| a & b);
=====================================output=====================================
type A = (number | string) & boolean
type B = (number | string) & boolean
type C = (number | string) & boolean
type D = (number | string) & boolean
let b1: C
let b2: C
let b3: C
let b4: C
let b5: C
let b6: /*1*/ C
let b7: /*1*/ C
let b8: /*1*/ C
let b9: /*1*/ C
let b10: /*1*/ /*2*/ C
let b11: /*1*/ /*2*/ C
let bb1: /*1*/ /*2*/ C & D
let bb2: /*1*/ /*2*/ C & /*3*/ D
let bb3: /*1*/ /*2*/ C & /*3*/ D /*5*/
type B2 = C
type B3 = C
type B4 = C
type B5 = C
type B6 = /*1*/ C
type B7 = /*1*/ C
type B8 = /*1*/ C
type B9 = /*1*/ C
type B10 = /*1*/ /*2*/ C
type B11 = /*1*/ /*2*/ C
type B12 = /*1*/ C
type Bb1 = /*1*/ /*2*/ C & D
type Bb2 = /*1*/ /*2*/ C & /*3*/ D
type Bb3 = /*1*/ /*2*/ C & /*3*/ D /*4*/
type D1 = /*1*/ a & b
type D2 = /*1*/ a & b
type D3 = /*1*/ a & b
type D4 = /*1*/ a & b
type D5 = /*1*/ a & b
type D6 /*0*/ = /*1*/ a & b
================================================================================
`;
exports[`intersection-parens.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
| printWidth
=====================================input======================================
type A = (number | string) & boolean;
type B = ((number | string)) & boolean;
type C = (((number | string))) & boolean;
type D = ((((number | string)))) & boolean;
let b1 : C;
let b2 : & C;
let b3 : (& C);
let b4 : & (C);
let b5 : (& (C));
let b6 : /*1*/ & C;
let b7 : /*1*/ & (C);
let b8 : /*1*/ (& C);
let b9 : (/*1*/ & C);
let b10: /*1*/ & /*2*/ C;
let b11: /*1*/ (& /*2*/ C);
let bb1: /*1*/ & /*2*/ C & D;
let bb2: /*1*/ & /*2*/ C & /*3*/ D;
let bb3: /*1*/ & /*2*/ C & /*3*/ D /*5*/;
type B2 = & C;
type B3 = (& C);
type B4 = & (C);
type B5 = (& (C));
type B6 = /*1*/ & C;
type B7 = /*1*/ & (C);
type B8 = /*1*/ (& C);
type B9 = (/*1*/ & C);
type B10 = /*1*/ & /*2*/ C;
type B11 = /*1*/ (& /*2*/ C);
type B12 = /*1*/ & ( (C));
type Bb1 = /*1*/ & /*2*/ C & D;
type Bb2 = /*1*/ & /*2*/ C & /*3*/ D;
type Bb3 = /*1*/ & /*2*/ C & /*3*/ D /*4*/;
type D1 = /*1*/ | a & b;
type D2 = /*1*/ | a & (b);
type D3 = /*1*/ | a & (| b);
type D4 = /*1*/ | (a & b);
type D5 = /*1*/ (| a & b);
type D6 /*0*/ = /*1*/ (| a & b);
=====================================output=====================================
type A = (number | string) & boolean;
type B = (number | string) & boolean;
type C = (number | string) & boolean;
type D = (number | string) & boolean;
let b1: C;
let b2: C;
let b3: C;
let b4: C;
let b5: C;
let b6: /*1*/ C;
let b7: /*1*/ C;
let b8: /*1*/ C;
let b9: /*1*/ C;
let b10: /*1*/ /*2*/ C;
let b11: /*1*/ /*2*/ C;
let bb1: /*1*/ /*2*/ C & D;
let bb2: /*1*/ /*2*/ C & /*3*/ D;
let bb3: /*1*/ /*2*/ C & /*3*/ D /*5*/;
type B2 = C;
type B3 = C;
type B4 = C;
type B5 = C;
type B6 = /*1*/ C;
type B7 = /*1*/ C;
type B8 = /*1*/ C;
type B9 = /*1*/ C;
type B10 = /*1*/ /*2*/ C;
type B11 = /*1*/ /*2*/ C;
type B12 = /*1*/ C;
type Bb1 = /*1*/ /*2*/ C & D;
type Bb2 = /*1*/ /*2*/ C & /*3*/ D;
type Bb3 = /*1*/ /*2*/ C & /*3*/ D /*4*/;
type D1 = /*1*/ a & b;
type D2 = /*1*/ a & b;
type D3 = /*1*/ a & b;
type D4 = /*1*/ a & b;
type D5 = /*1*/ a & b;
type D6 /*0*/ = /*1*/ a & b;
================================================================================
`;
exports[`type-arguments.ts - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["typescript"]
@@ -16,3 +16,101 @@ type A1 = /* 4 */ (A & B)[];
================================================================================
`;
exports[`intersection-parens.ts format 1`] = `
====================================options=====================================
parsers: ["typescript", "flow"]
printWidth: 80
| printWidth
=====================================input======================================
type A = (number | string) & boolean;
type B = ((number | string)) & boolean;
type C = (((number | string))) & boolean;
type D = ((((number | string)))) & boolean;
let b1 : C;
let b2 : & C;
let b3 : (& C);
let b4 : & (C);
let b5 : (& (C));
let b6 : /*1*/ & C;
let b7 : /*1*/ & (C);
let b8 : /*1*/ (& C);
let b9 : (/*1*/ & C);
let b10: /*1*/ & /*2*/ C;
let b11: /*1*/ (& /*2*/ C);
let bb1: /*1*/ & /*2*/ C & D;
let bb2: /*1*/ & /*2*/ C & /*3*/ D;
let bb3: /*1*/ & /*2*/ C & /*3*/ D /*5*/;
type B2 = & C;
type B3 = (& C);
type B4 = & (C);
type B5 = (& (C));
type B6 = /*1*/ & C;
type B7 = /*1*/ & (C);
type B8 = /*1*/ (& C);
type B9 = (/*1*/ & C);
type B10 = /*1*/ & /*2*/ C;
type B11 = /*1*/ (& /*2*/ C);
type B12 = /*1*/ & ( (C));
type Bb1 = /*1*/ & /*2*/ C & D;
type Bb2 = /*1*/ & /*2*/ C & /*3*/ D;
type Bb3 = /*1*/ & /*2*/ C & /*3*/ D /*4*/;
type D1 = /*1*/ | a & b;
type D2 = /*1*/ | a & (b);
type D3 = /*1*/ | a & (| b);
type D4 = /*1*/ | (a & b);
type D5 = /*1*/ (| a & b);
type D6 /*0*/ = /*1*/ (| a & b);
=====================================output=====================================
type A = (number | string) & boolean;
type B = (number | string) & boolean;
type C = (number | string) & boolean;
type D = (number | string) & boolean;
let b1: C;
let b2: C;
let b3: C;
let b4: C;
let b5: C;
let b6: /*1*/ C;
let b7: /*1*/ C;
let b8: /*1*/ C;
let b9: /*1*/ C;
let b10: /*1*/ /*2*/ C;
let b11: /*1*/ /*2*/ C;
let bb1: /*1*/ /*2*/ C & D;
let bb2: /*1*/ /*2*/ C & /*3*/ D;
let bb3: /*1*/ /*2*/ C & /*3*/ D /*5*/;
type B2 = C;
type B3 = C;
type B4 = C;
type B5 = C;
type B6 /*1*/ = C;
type B7 /*1*/ = C;
type B8 /*1*/ = C;
type B9 /*1*/ = C;
type B10 /*1*/ = /*2*/ C;
type B11 /*1*/ = /*2*/ C;
type B12 /*1*/ = C;
type Bb1 = /*1*/ /*2*/ C & D;
type Bb2 = /*1*/ /*2*/ C & /*3*/ D;
type Bb3 = /*1*/ /*2*/ C & /*3*/ D /*4*/;
type D1 /*1*/ = a & b;
type D2 /*1*/ = a & b;
type D3 /*1*/ = a & b;
type D4 /*1*/ = a & b;
type D5 /*1*/ = a & b;
type D6 /*0*/ /*1*/ = a & b;
================================================================================
`;
@@ -1,37 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`comments.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
| printWidth
=====================================input======================================
type A1 = a /* 1 */ | b;
type A2 = a | /* 1 */ b;
type A3 = (a /* 1 */) | b;
type A4 = a | (/* 1 */ b);
type A5 = (a) /* 1 */ | b;
type A6 = a | /* 1 */ (b);
type B1 = a /* 1 */ /* 2 */ | b;
type B2 = a /* 1 */ | /* 2 */ b;
type B3 = a | /* 1 */ /* 2 */ b;
=====================================output=====================================
type A1 = a /* 1 */ | b;
type A2 = a | /* 1 */ b;
type A3 = a /* 1 */ | b;
type A4 = a | /* 1 */ b;
type A5 = a /* 1 */ | b;
type A6 = a | /* 1 */ b;
type B1 = a /* 1 */ /* 2 */ | b;
type B2 = a /* 1 */ | /* 2 */ b;
type B3 = a | /* 1 */ /* 2 */ b;
================================================================================
`;
exports[`inlining.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
@@ -181,68 +149,6 @@ type T8 = number | ((arg: any) => void);
================================================================================
`;
exports[`prettier-ignore.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
| printWidth
=====================================input======================================
export type a =
// foo
| foo1&foo2
// bar
| bar1&bar2
// prettier-ignore
| qux1&qux2;
export type a =
// foo
| foo1&foo2
// bar
| bar1&bar2
// prettier-ignore
| qux1&qux2
// baz
| baz1&baz2;
export type a =
// prettier-ignore
| foo1&foo2
// bar
| bar1&bar2
// qux
| qux1&qux2;
=====================================output=====================================
export type a =
// foo
| (foo1 & foo2)
// bar
| (bar1 & bar2)
// prettier-ignore
| (qux1&qux2);
export type a =
// foo
| (foo1 & foo2)
// bar
| (bar1 & bar2)
// prettier-ignore
| (qux1&qux2)
// baz
| (baz1 & baz2);
export type a =
// prettier-ignore
| (foo1&foo2)
// bar
| (bar1 & bar2)
// qux
| (qux1 & qux2);
================================================================================
`;
exports[`union-parens.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
@@ -449,13 +355,13 @@ type A2 = C;
type A3 = C;
type A4 = C;
type A5 = C;
type A6 = /*1*/ C;
type A7 = /*1*/ C;
type A8 = /*1*/ C;
type A9 = /*1*/ C;
type A10 = /*1*/ /*2*/ C;
type A11 = /*1*/ /*2*/ C;
type A12 = /*1*/ C;
type A6 /*1*/ = C;
type A7 /*1*/ = C;
type A8 /*1*/ = C;
type A9 /*1*/ = C;
type A10 /*1*/ = /*2*/ C;
type A11 /*1*/ = /*2*/ C;
type A12 /*1*/ = C;
type A13 = /*1*/ C;
type Aa1 = /*1*/ /*2*/ C | D;
@@ -465,7 +371,7 @@ type Aa3 = /*1*/ /*2*/ C | /*3*/ D /*4*/;
type C1 = /*1*/ a | b;
type C2 = /*1*/ a | b;
type C3 = /*1*/ a | b;
type C4 = /*1*/ a | b;
type C4 /*1*/ = a | b;
type C5 = /*1*/ a | b;
type C6 /*0*/ = /*1*/ a | b;
@@ -503,171 +409,3 @@ type GetChatsSagaEffects =
================================================================================
`;
exports[`within-tuple.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
| printWidth
=====================================input======================================
type A = [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD]
type B = [
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
]
type B1 = [
(
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
)
]
type C = [
| [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD]
| [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD]
]
type D = [
(AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD),
(AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD)
]
type D1 = [
(
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
),
(
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
)
]
type D2 = [
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD,
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
]
type E = [ AA | BB, AA | BB ]
type F = [
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD,
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
]
=====================================output=====================================
type A = [
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD,
];
type B = [
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD,
];
type B1 = [
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD,
];
type C = [
| [
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD,
]
| [
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD,
],
];
type D = [
(
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
),
(
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
),
];
type D1 = [
(
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
),
(
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
),
];
type D2 = [
(
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
),
(
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
),
];
type E = [AA | BB, AA | BB];
type F = [
(
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
),
AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB,
];
================================================================================
`;
@@ -16,3 +16,397 @@ type A1 = /* 4 */ (A | B)[];
================================================================================
`;
exports[`comments.ts format 1`] = `
====================================options=====================================
parsers: ["typescript", "flow"]
printWidth: 80
| printWidth
=====================================input======================================
type A1 = a /* 1 */ | b;
type A2 = a | /* 1 */ b;
type A3 = (a /* 1 */) | b;
type A4 = a | (/* 1 */ b);
type A5 = (a) /* 1 */ | b;
type A6 = a | /* 1 */ (b);
type B1 = a /* 1 */ /* 2 */ | b;
type B2 = a /* 1 */ | /* 2 */ b;
type B3 = a | /* 1 */ /* 2 */ b;
=====================================output=====================================
type A1 = a /* 1 */ | b;
type A2 = a | /* 1 */ b;
type A3 = a /* 1 */ | b;
type A4 = a | /* 1 */ b;
type A5 = a /* 1 */ | b;
type A6 = a | /* 1 */ b;
type B1 = a /* 1 */ /* 2 */ | b;
type B2 = a /* 1 */ | /* 2 */ b;
type B3 = a | /* 1 */ /* 2 */ b;
================================================================================
`;
exports[`prettier-ignore.ts format 1`] = `
====================================options=====================================
parsers: ["typescript", "flow"]
printWidth: 80
| printWidth
=====================================input======================================
export type a =
// foo
| foo1&foo2
// bar
| bar1&bar2
// prettier-ignore
| qux1&qux2;
export type b =
// foo
| foo1&foo2
// bar
| bar1&bar2
// prettier-ignore
| qux1&qux2
// baz
| baz1&baz2;
export type c =
// prettier-ignore
| foo1&foo2
// bar
| bar1&bar2
// qux
| qux1&qux2;
=====================================output=====================================
export type a =
// foo
| (foo1 & foo2)
// bar
| (bar1 & bar2)
// prettier-ignore
| (qux1&qux2);
export type b =
// foo
| (foo1 & foo2)
// bar
| (bar1 & bar2)
// prettier-ignore
| (qux1&qux2)
// baz
| (baz1 & baz2);
export type c =
// prettier-ignore
| (foo1&foo2)
// bar
| (bar1 & bar2)
// qux
| (qux1 & qux2);
================================================================================
`;
exports[`single-type.ts format 1`] = `
====================================options=====================================
parsers: ["typescript", "flow"]
printWidth: 80
| printWidth
=====================================input======================================
type A1 =
| (
| (
| (
| A
// A comment to force break
| B
)
)
);
type A2 =
| (
| (
| A
// A comment to force break
| B
)
| (
| A
// A comment to force break
| B
)
);
type A3 =
| ( | (
| A
// A comment to force break
| B
) );
type A4 =
| ( | ( | (
| A
// A comment to force break
| B
) ) );
type A5 =
| (
| (
| { key: string }
| { key: string }
| { key: string }
| { key: string }
)
| { key: string }
| { key: string }
);
type A6 = | (
/*1*/ | (
| (
| A
// A comment to force break
| B
)
)
);
type B1 =
| (
& (
(
| A
// A comment to force break
| B
)
)
);
type B2 =
| (
& (
| (
& (
(
| A
// A comment to force break
| B
)
)
)
)
);
=====================================output=====================================
type A1 =
| A
// A comment to force break
| B;
type A2 =
| (
| A
// A comment to force break
| B
)
| (
| A
// A comment to force break
| B
);
type A3 =
| A
// A comment to force break
| B;
type A4 =
| A
// A comment to force break
| B;
type A5 =
| ({ key: string } | { key: string } | { key: string } | { key: string })
| { key: string }
| { key: string };
type A6 = /*1*/
| A
// A comment to force break
| B;
type B1 =
| A
// A comment to force break
| B;
type B2 =
| A
// A comment to force break
| B;
================================================================================
`;
exports[`within-tuple.ts format 1`] = `
====================================options=====================================
parsers: ["typescript", "flow"]
printWidth: 80
| printWidth
=====================================input======================================
type A = [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD]
type B = [
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
]
type B1 = [
(
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
)
]
type C = [
| [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD]
| [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD]
]
type D = [
(AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD),
(AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD)
]
type D1 = [
(
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
),
(
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
)
]
type D2 = [
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD,
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
]
type E = [ AA | BB, AA | BB ]
type F = [
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD,
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
]
=====================================output=====================================
type A = [
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD,
];
type B = [
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD,
];
type B1 = [
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD,
];
type C = [
| [
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD,
]
| [
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD,
],
];
type D = [
(
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
),
(
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
),
];
type D1 = [
(
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
),
(
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
),
];
type D2 = [
(
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
),
(
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
),
];
type E = [AA | BB, AA | BB];
type F = [
(
| AAAAAAAAAAAAAAAAAAAAAA
| BBBBBBBBBBBBBBBBBBBBBB
| CCCCCCCCCCCCCCCCCCCCCC
| DDDDDDDDDDDDDDDDDDDDDD
),
AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB,
];
================================================================================
`;
@@ -6,7 +6,7 @@ export type a =
// prettier-ignore
| qux1&qux2;
export type a =
export type b =
// foo
| foo1&foo2
// bar
@@ -16,7 +16,7 @@ export type a =
// baz
| baz1&baz2;
export type a =
export type c =
// prettier-ignore
| foo1&foo2
// bar
@@ -0,0 +1,80 @@
type A1 =
| (
| (
| (
| A
// A comment to force break
| B
)
)
);
type A2 =
| (
| (
| A
// A comment to force break
| B
)
| (
| A
// A comment to force break
| B
)
);
type A3 =
| ( | (
| A
// A comment to force break
| B
) );
type A4 =
| ( | ( | (
| A
// A comment to force break
| B
) ) );
type A5 =
| (
| (
| { key: string }
| { key: string }
| { key: string }
| { key: string }
)
| { key: string }
| { key: string }
);
type A6 = | (
/*1*/ | (
| (
| A
// A comment to force break
| B
)
)
);
type B1 =
| (
& (
(
| A
// A comment to force break
| B
)
)
);
type B2 =
| (
& (
| (
& (
(
| A
// A comment to force break
| B
)
)
)
)
);
@@ -0,0 +1,22 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`single-type.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
| printWidth
=====================================input======================================
type A1 =
/* 1 */ | /* 2 */ (
/* 3 */ | /* 4 */ {
key: string;
}
);
=====================================output=====================================
type A1 /* 2 */ = /* 1 */ /* 3 */ /* 4 */ {
key: string;
};
================================================================================
`;
@@ -0,0 +1 @@
run_spec(import.meta, ["typescript"]);
@@ -0,0 +1,6 @@
type A1 =
/* 1 */ | /* 2 */ (
/* 3 */ | /* 4 */ {
key: string;
}
);