Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions crates/oxc_formatter/src/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ use self::{
object_like::ObjectLike,
object_pattern_like::ObjectPatternLike,
parameters::{ParameterLayout, ParameterList},
return_or_throw_statement::FormatAdjacentArgument,
semicolon::OptionalSemicolon,
type_parameters::{FormatTSTypeParameters, FormatTSTypeParametersOptions},
utils::{
Expand Down Expand Up @@ -935,12 +936,9 @@ impl<'a> FormatWrite<'a, FormatJsArrowFunctionExpressionOptions>

impl<'a> FormatWrite<'a> for AstNode<'a, YieldExpression<'a>> {
fn write(&self, f: &mut Formatter<'_, 'a>) -> FormatResult<()> {
write!(f, "yield")?;
if self.delegate() {
write!(f, "*")?;
}
write!(f, ["yield", self.delegate().then_some("*")])?;
if let Some(argument) = &self.argument() {
write!(f, [space(), argument])?;
write!(f, [space(), FormatAdjacentArgument(argument)])?;
}
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_formatter/src/write/return_or_throw_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<'a> Format<'a> for ReturnAndThrowStatement<'a, '_> {
write!(f, self.keyword())?;

if let Some(argument) = self.argument() {
write!(f, [space(), FormatReturnOrThrowArgument(argument)])?;
write!(f, [space(), FormatAdjacentArgument(argument)])?;
}

let dangling_comments = f.context().comments().comments_before(self.span().end);
Expand All @@ -84,9 +84,9 @@ impl<'a> Format<'a> for ReturnAndThrowStatement<'a, '_> {
}
}

pub struct FormatReturnOrThrowArgument<'a, 'b>(&'b AstNode<'a, Expression<'a>>);
pub struct FormatAdjacentArgument<'a, 'b>(pub &'b AstNode<'a, Expression<'a>>);

impl<'a> Format<'a> for FormatReturnOrThrowArgument<'a, '_> {
impl<'a> Format<'a> for FormatAdjacentArgument<'a, '_> {
fn fmt(&self, f: &mut Formatter<'_, 'a>) -> FormatResult<()> {
let argument = self.0;

Expand Down
60 changes: 60 additions & 0 deletions crates/oxc_formatter/tests/fixtures/js/comments/yield.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
function *t1() {
yield (
// comment
a as any
);
}
function *t2() {
yield (
// comment
a as any
) + 1;
}
function *t3() {
yield (
// comment
a as any
) ? 0 : 1;
}
function *t4() {
yield (
// comment
a as any
).b;
}
function *t5() {
yield (
// comment
a as any
)[a];
}
function *t6() {
yield (
// comment
a as any
)();
}
function *t7() {
yield (
// comment
a as any
)``;
}
function *t8() {
yield (
// comment
a as any
) as any;
}
function *t9() {
yield (
// comment
a as any
) satisfies any;
}
function *t10() {
yield (
// comment
a as any
)!;
}
68 changes: 68 additions & 0 deletions crates/oxc_formatter/tests/fixtures/js/comments/yield.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
source: crates/oxc_formatter/tests/fixtures/mod.rs
---
==================== Input ====================
function *t1() {
yield (
// comment
a as any
);
}
function *t2() {
yield (
// comment
a as any
) + 1;
}
function *t3() {
yield (
// comment
a as any
) ? 0 : 1;
}
function *t4() {
yield (
// comment
a as any
).b;
}
function *t5() {
yield (
// comment
a as any
)[a];
}
function *t6() {
yield (
// comment
a as any
)();
}
function *t7() {
yield (
// comment
a as any
)``;
}
function *t8() {
yield (
// comment
a as any
) as any;
}
function *t9() {
yield (
// comment
a as any
) satisfies any;
}
function *t10() {
yield (
// comment
a as any
)!;
}

==================== Output ====================

===================== End =====================
60 changes: 60 additions & 0 deletions crates/oxc_formatter/tests/fixtures/ts/comments/yield.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
function *t1() {
yield (
// comment
a as any
);
}
function *t2() {
yield (
// comment
a as any
) + 1;
}
function *t3() {
yield (
// comment
a as any
) ? 0 : 1;
}
function *t4() {
yield (
// comment
a as any
).b;
}
function *t5() {
yield (
// comment
a as any
)[a];
}
function *t6() {
yield (
// comment
a as any
)();
}
function *t7() {
yield (
// comment
a as any
)``;
}
function *t8() {
yield (
// comment
a as any
) as any;
}
function *t9() {
yield (
// comment
a as any
) satisfies any;
}
function *t10() {
yield (
// comment
a as any
)!;
}
130 changes: 130 additions & 0 deletions crates/oxc_formatter/tests/fixtures/ts/comments/yield.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---
source: crates/oxc_formatter/tests/fixtures/mod.rs
---
==================== Input ====================
function *t1() {
yield (
// comment
a as any
);
}
function *t2() {
yield (
// comment
a as any
) + 1;
}
function *t3() {
yield (
// comment
a as any
) ? 0 : 1;
}
function *t4() {
yield (
// comment
a as any
).b;
}
function *t5() {
yield (
// comment
a as any
)[a];
}
function *t6() {
yield (
// comment
a as any
)();
}
function *t7() {
yield (
// comment
a as any
)``;
}
function *t8() {
yield (
// comment
a as any
) as any;
}
function *t9() {
yield (
// comment
a as any
) satisfies any;
}
function *t10() {
yield (
// comment
a as any
)!;
}

==================== Output ====================
function* t1() {
yield (
// comment
a as any
);
}
function* t2() {
yield (
// comment
(a as any) + 1
);
}
function* t3() {
yield (
// comment
(a as any)
? 0
: 1
);
}
function* t4() {
yield (
// comment
(a as any).b
);
}
function* t5() {
yield (
// comment
(a as any)[a]
);
}
function* t6() {
yield (
// comment
(a as any)()
);
}
function* t7() {
yield (
// comment
(a as any)``
);
}
function* t8() {
yield (
// comment
a as any as any
);
}
function* t9() {
yield (
// comment
a as any satisfies any
);
}
function* t10() {
yield (
// comment
(a as any)!
);
}

===================== End =====================
Loading