From 21c4285fa11186c4637c4198a2284ff2f3a454a1 Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Mon, 20 Oct 2025 08:48:29 +0000 Subject: [PATCH] fix(formatter): correct printing remaining trailing comments for `TSMappedType` (#14761) --- .../oxc_formatter/src/formatter/comments.rs | 2 +- .../tests/fixtures/ts/comments/mapped-type.ts | 6 ++++++ .../fixtures/ts/comments/mapped-type.ts.snap | 20 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 crates/oxc_formatter/tests/fixtures/ts/comments/mapped-type.ts create mode 100644 crates/oxc_formatter/tests/fixtures/ts/comments/mapped-type.ts.snap diff --git a/crates/oxc_formatter/src/formatter/comments.rs b/crates/oxc_formatter/src/formatter/comments.rs index 5efa718b47080..534fcd4d46cfa 100644 --- a/crates/oxc_formatter/src/formatter/comments.rs +++ b/crates/oxc_formatter/src/formatter/comments.rs @@ -323,7 +323,7 @@ impl<'a> Comments<'a> { } if !source_text.all_bytes_match(start, comment.span.start, |b| { - b.is_ascii_whitespace() || matches!(b, b')' | b',') + b.is_ascii_whitespace() || matches!(b, b')' | b',' | b';') }) { return &comments[..idx]; } diff --git a/crates/oxc_formatter/tests/fixtures/ts/comments/mapped-type.ts b/crates/oxc_formatter/tests/fixtures/ts/comments/mapped-type.ts new file mode 100644 index 0000000000000..480822d4bfe51 --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/ts/comments/mapped-type.ts @@ -0,0 +1,6 @@ +type _Test = { + [T in number]: T; + // If there are any BinaryOperator members that don't have a corresponding + // BinaryOperatorToText, then this line will error with "Type 'T' cannot + // be used to index type 'BinaryOperatorToText'." +}; diff --git a/crates/oxc_formatter/tests/fixtures/ts/comments/mapped-type.ts.snap b/crates/oxc_formatter/tests/fixtures/ts/comments/mapped-type.ts.snap new file mode 100644 index 0000000000000..3e3f02bc6ccea --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/ts/comments/mapped-type.ts.snap @@ -0,0 +1,20 @@ +--- +source: crates/oxc_formatter/tests/fixtures/mod.rs +--- +==================== Input ==================== +type _Test = { + [T in number]: T; + // If there are any BinaryOperator members that don't have a corresponding + // BinaryOperatorToText, then this line will error with "Type 'T' cannot + // be used to index type 'BinaryOperatorToText'." +}; + +==================== Output ==================== +type _Test = { + [T in number]: T; + // If there are any BinaryOperator members that don't have a corresponding + // BinaryOperatorToText, then this line will error with "Type 'T' cannot + // be used to index type 'BinaryOperatorToText'." +}; + +===================== End =====================