Fix comment placement in assignment-like type aliases (TSTypeAliasDeclaration) (#19410)

Co-authored-by: WhoamiI00 <anktiisop12@gmail.com>
Co-authored-by: fisker <lionkay@gmail.com>
This commit is contained in:
authored and GitHub committed 2026-06-24 17:43:11 +08:00
1 parent d1c3f659ee
commit 61f09e4484
10 files changed
+366 -62

No files matched your search

@@ -16,7 +16,6 @@ const unstableTests = new Map(
(options) => options.proseWrap === "always",
],
"flow/hook/declare-hook.js",
"flow/hook/comments-before-arrow.js",
"flow/hook/hook-type-annotation.js",
"flow/comments/type_annotations.js",
"typescript/prettier-ignore/mapped-types.ts",
@@ -192,25 +192,25 @@ 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;
type Aa2 = /*1*/ /*2*/ C & /*3*/ D;
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 C5 /*1*/ = a & b;
type C6 /*0*/ /*1*/ = a & b;
type C1 = /*1*/ a & b;
type C2 = /*1*/ a & b;
type C3 = /*1*/ a & b;
type C4 = /*1*/ a & b;
type C5 = /*1*/ a & b;
type C6 /*0*/ = /*1*/ a & b;
type Ctor = (new () => X) & Y;
@@ -409,25 +409,25 @@ 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
type Aa2 = /*1*/ /*2*/ C & /*3*/ D
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 C5 /*1*/ = a & b
type C6 /*0*/ /*1*/ = a & b
type C1 = /*1*/ a & b
type C2 = /*1*/ a & b
type C3 = /*1*/ a & b
type C4 = /*1*/ a & b
type C5 = /*1*/ a & b
type C6 /*0*/ = /*1*/ a & b
type Ctor = (new () => X) & Y
@@ -625,25 +625,25 @@ 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;
type Aa2 = /*1*/ /*2*/ C & /*3*/ D;
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 C5 /*1*/ = a & b;
type C6 /*0*/ /*1*/ = a & b;
type C1 = /*1*/ a & b;
type C2 = /*1*/ a & b;
type C3 = /*1*/ a & b;
type C4 = /*1*/ a & b;
type C5 = /*1*/ a & b;
type C6 /*0*/ = /*1*/ a & b;
type Ctor = (new () => X) & Y;
@@ -91,24 +91,135 @@ 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 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;
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[`single-member.ts format 1`] = `
====================================options=====================================
parsers: ["typescript", "flow"]
printWidth: 80 (default) |
=====================================input======================================
// https://github.com/oxc-project/oxc/pull/21915
// export type aType = & // Comment
// "VALUE";
export type bType = &
// Comment
"VALUE";
export type cType = & /* Comment */
"VALUE";
export type dType = /* Comment */
& "VALUE";
// export type eType = // Comment
// & "VALUE";
export type fType = &
/* Comment */
"VALUE";
export type gType = &
// Comment
// Comment
"VALUE";
export type hType = &
"VALUE";
export type iType = /* Comment */ /* Comment */ & "VALUE";
export type jType = /* Comment */
/* Comment */ & "VALUE";
export type kType = /* Comment */
&
// Comment
"VALUE";
export type lType = /* Comment */ &
// Comment
"VALUE";
export type mType = & "VALUE" /* Comment */;
export type nType = // Comment
& /* Comment */
"VALUE";
// type oType = // Comment
// & // Comment
// "VALUE"
=====================================output=====================================
// https://github.com/oxc-project/oxc/pull/21915
// export type aType = & // Comment
// "VALUE";
export type bType =
// Comment
"VALUE";
export type cType = /* Comment */ "VALUE";
export type dType = /* Comment */ "VALUE";
// export type eType = // Comment
// & "VALUE";
export type fType =
/* Comment */
"VALUE";
export type gType =
// Comment
// Comment
"VALUE";
export type hType = "VALUE";
export type iType = /* Comment */ /* Comment */ "VALUE";
export type jType = /* Comment */ /* Comment */ "VALUE";
export type kType =
/* Comment */
// Comment
"VALUE";
export type lType =
/* Comment */ // Comment
"VALUE";
export type mType = "VALUE"; /* Comment */
export type nType = /* Comment */ "VALUE"; // Comment
// type oType = // Comment
// & // Comment
// "VALUE"
================================================================================
`;
@@ -0,0 +1,53 @@
// https://github.com/oxc-project/oxc/pull/21915
// export type aType = & // Comment
// "VALUE";
export type bType = &
// Comment
"VALUE";
export type cType = & /* Comment */
"VALUE";
export type dType = /* Comment */
& "VALUE";
// export type eType = // Comment
// & "VALUE";
export type fType = &
/* Comment */
"VALUE";
export type gType = &
// Comment
// Comment
"VALUE";
export type hType = &
"VALUE";
export type iType = /* Comment */ /* Comment */ & "VALUE";
export type jType = /* Comment */
/* Comment */ & "VALUE";
export type kType = /* Comment */
&
// Comment
"VALUE";
export type lType = /* Comment */ &
// Comment
"VALUE";
export type mType = & "VALUE" /* Comment */;
export type nType = // Comment
& /* Comment */
"VALUE";
// type oType = // Comment
// & // Comment
// "VALUE"
@@ -567,13 +567,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;
@@ -583,7 +583,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;
@@ -1,5 +1,34 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`comments.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80 (default) |
=====================================input======================================
// https://github.com/prettier/prettier/issues/18834
type A1 = /* 1 */ | T1;
type A2 = /* 1 */ | (T2);
type A3 = (/* 1 */ | T3);
type A4 = /* 1 */ | /* 2 */ T4;
type A5 = /* 1 */ | (/* 2 */ T5);
type A6 = /* 0 */ /* 1 */ | /* 2 */ T6;
type A7 = /* 0 */ | /* 1 */ T7;
type A8 /* = */ /* 1:before */ = /* 2 */ | /* 3 */ T7;
=====================================output=====================================
// https://github.com/prettier/prettier/issues/18834
type A1 = /* 1 */ T1;
type A2 = /* 1 */ T2;
type A3 = /* 1 */ T3;
type A4 = /* 1 */ /* 2 */ T4;
type A5 = /* 1 */ /* 2 */ T5;
type A6 = /* 0 */ /* 1 */ /* 2 */ T6;
type A7 = /* 0 */ /* 1 */ T7;
type A8 /* = */ /* 1:before */ = /* 2 */ /* 3 */ T7;
================================================================================
`;
exports[`single-type.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
@@ -13,9 +42,51 @@ type A1 =
);
=====================================output=====================================
type A1 /* 2 */ = /* 1 */ /* 3 */ /* 4 */ {
type A1 = /* 1 */ /* 2 */ /* 3 */ /* 4 */ {
key: string;
};
================================================================================
`;
exports[`single-type-2.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80 (default) |
=====================================input======================================
// https://github.com/oxc-project/oxc/pull/21915
export type myType = | // Comment
"A";
// Block comment same-line after pipe
type BlockComment = | /* block */
"B";
// Same-line comment then own-line comment
type Mixed = | // first
// second
"C";
// Long line comment that exceeds printWidth on the \`=\` line
type LongType = | // This is a really long comment that might exceed the print width limit
"A";
=====================================output=====================================
// https://github.com/oxc-project/oxc/pull/21915
export type myType = // Comment
"A";
// Block comment same-line after pipe
type BlockComment = /* block */ "B";
// Same-line comment then own-line comment
type Mixed = // first
// second
"C";
// Long line comment that exceeds printWidth on the \`=\` line
type LongType = // This is a really long comment that might exceed the print width limit
"A";
================================================================================
`;
@@ -0,0 +1,9 @@
// https://github.com/prettier/prettier/issues/18834
type A1 = /* 1 */ | T1;
type A2 = /* 1 */ | (T2);
type A3 = (/* 1 */ | T3);
type A4 = /* 1 */ | /* 2 */ T4;
type A5 = /* 1 */ | (/* 2 */ T5);
type A6 = /* 0 */ /* 1 */ | /* 2 */ T6;
type A7 = /* 0 */ | /* 1 */ T7;
type A8 /* = */ /* 1:before */ = /* 2 */ | /* 3 */ T7;
@@ -0,0 +1,16 @@
// https://github.com/oxc-project/oxc/pull/21915
export type myType = | // Comment
"A";
// Block comment same-line after pipe
type BlockComment = | /* block */
"B";
// Same-line comment then own-line comment
type Mixed = | // first
// second
"C";
// Long line comment that exceeds printWidth on the `=` line
type LongType = | // This is a really long comment that might exceed the print width limit
"A";