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 =====================