From ae43bcf68c905f7f911a3ad03ca2dbfa3f0b690c Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Sat, 11 Oct 2025 02:58:57 +0800 Subject: [PATCH] Add tests to close issue 16121 (#18040) --- tests/format/typescript/comments/16121.ts | 38 +++++++++ .../__snapshots__/format.test.js.snap | 85 +++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 tests/format/typescript/comments/16121.ts diff --git a/tests/format/typescript/comments/16121.ts b/tests/format/typescript/comments/16121.ts new file mode 100644 index 000000000..54c275371 --- /dev/null +++ b/tests/format/typescript/comments/16121.ts @@ -0,0 +1,38 @@ +export type IntersectionType = + & FirstPart + // Presence of comment makes this non-idempotent + & { + an: string, + object: string, + type: string, + } + + +export type IntersectionType = + & FirstPart + // Comment Line 1 + // Comment Line 2 + & { + an: string, + object: string, + type: string, + } + +export type IntersectionType = + | FirstPart + // Presence of comment is not a problem + | { + an: string; + object: string; + type: string; + }; + +export type IntersectionType = + | FirstPart + // Comment Line 1 + // Comment Line 2 + | { + an: string; + object: string; + type: string; + }; diff --git a/tests/format/typescript/comments/__snapshots__/format.test.js.snap b/tests/format/typescript/comments/__snapshots__/format.test.js.snap index fb6fbbe9c..a355bf9b9 100644 --- a/tests/format/typescript/comments/__snapshots__/format.test.js.snap +++ b/tests/format/typescript/comments/__snapshots__/format.test.js.snap @@ -250,6 +250,91 @@ class Foo { ================================================================================ `; +exports[`16121.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +export type IntersectionType = + & FirstPart + // Presence of comment makes this non-idempotent + & { + an: string, + object: string, + type: string, + } + + +export type IntersectionType = + & FirstPart + // Comment Line 1 + // Comment Line 2 + & { + an: string, + object: string, + type: string, + } + +export type IntersectionType = + | FirstPart + // Presence of comment is not a problem + | { + an: string; + object: string; + type: string; + }; + +export type IntersectionType = + | FirstPart + // Comment Line 1 + // Comment Line 2 + | { + an: string; + object: string; + type: string; + }; + +=====================================output===================================== +export type IntersectionType = FirstPart & + // Presence of comment makes this non-idempotent + { + an: string; + object: string; + type: string; + }; + +export type IntersectionType = FirstPart & + // Comment Line 1 + // Comment Line 2 + { + an: string; + object: string; + type: string; + }; + +export type IntersectionType = + | FirstPart + // Presence of comment is not a problem + | { + an: string; + object: string; + type: string; + }; + +export type IntersectionType = + | FirstPart + // Comment Line 1 + // Comment Line 2 + | { + an: string; + object: string; + type: string; + }; + +================================================================================ +`; + exports[`16207.ts format 1`] = ` ====================================options===================================== parsers: ["typescript"]