diff --git a/crates/oxc_formatter/src/formatter/comments.rs b/crates/oxc_formatter/src/formatter/comments.rs index 728e05f2b1ca8..77f5a7c230ae7 100644 --- a/crates/oxc_formatter/src/formatter/comments.rs +++ b/crates/oxc_formatter/src/formatter/comments.rs @@ -344,9 +344,7 @@ impl<'a> Comments<'a> { // Stop if the comment: // 1. is over the following node // 2. is after the enclosing node, which means the comment should be printed in the parent node. - if comment.span.end > following_span.start - || (comment.span.end > enclosing_span.end && enclosing_span != preceding_span) - { + if comment.span.end > following_span.start || comment.span.end > enclosing_span.end { break; } diff --git a/crates/oxc_formatter/src/write/mapped_type.rs b/crates/oxc_formatter/src/write/mapped_type.rs index b3b2f911dac0d..fefeb92229a4a 100644 --- a/crates/oxc_formatter/src/write/mapped_type.rs +++ b/crates/oxc_formatter/src/write/mapped_type.rs @@ -56,6 +56,7 @@ impl<'a> FormatWrite<'a> for AstNode<'a, TSMappedType<'a>> { if let Some(name_type) = &name_type { write!(f, [space(), "as", space(), name_type])?; } + type_parameter.format_trailing_comments(f)?; write!(f, "]")?; if let Some(optional) = self.optional() { write!( diff --git a/crates/oxc_formatter/src/write/try_statement.rs b/crates/oxc_formatter/src/write/try_statement.rs index 63e5571b9ed3f..2af8fbf833ba1 100644 --- a/crates/oxc_formatter/src/write/try_statement.rs +++ b/crates/oxc_formatter/src/write/try_statement.rs @@ -115,6 +115,8 @@ impl<'a> FormatWrite<'a> for AstNode<'a, CatchParameter<'a>> { write!(f, self.pattern())?; } + self.format_trailing_comments(f)?; + write!(f, ")") } } diff --git a/crates/oxc_formatter/tests/fixtures/ts/comments/as.ts b/crates/oxc_formatter/tests/fixtures/ts/comments/as.ts new file mode 100644 index 0000000000000..586e90fb1d518 --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/ts/comments/as.ts @@ -0,0 +1,2 @@ +(activeService as unknown as QuickInputController) /* TS fail */ + .pick(); diff --git a/crates/oxc_formatter/tests/fixtures/ts/comments/as.ts.snap b/crates/oxc_formatter/tests/fixtures/ts/comments/as.ts.snap new file mode 100644 index 0000000000000..1b4290c106295 --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/ts/comments/as.ts.snap @@ -0,0 +1,12 @@ +--- +source: crates/oxc_formatter/tests/fixtures/mod.rs +--- +==================== Input ==================== +(activeService as unknown as QuickInputController) /* TS fail */ + .pick(); + +==================== Output ==================== +(activeService as unknown as QuickInputController) /* TS fail */ + .pick(); + +===================== End =====================