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
40 changes: 39 additions & 1 deletion crates/oxc_formatter/src/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,45 @@ impl<'a> FormatWrite<'a> for AstNode<'a, Super> {

impl<'a> FormatWrite<'a> for AstNode<'a, AwaitExpression<'a>> {
fn write(&self, f: &mut Formatter<'_, 'a>) -> FormatResult<()> {
write!(f, ["await", space(), self.argument()])
let format_inner = format_with(|f| write!(f, ["await", space(), self.argument()]));

let is_callee_or_object = match self.parent {
AstNodes::CallExpression(_)
| AstNodes::NewExpression(_)
| AstNodes::StaticMemberExpression(_) => true,
AstNodes::ComputedMemberExpression(member) => member.object.span() == self.span(),
_ => false,
};

if is_callee_or_object {
let mut parent = self.parent.parent();
let mut ancestor_is_await = false;
loop {
match parent {
AstNodes::AwaitExpression(_)
| AstNodes::BlockStatement(_)
| AstNodes::FunctionBody(_)
| AstNodes::SwitchCase(_)
| AstNodes::Program(_)
| AstNodes::TSModuleBlock(_) => break,
_ => parent = parent.parent(),
}
}

let indented = format_with(|f| write!(f, [soft_block_indent(&format_inner)]));

return if let AstNodes::AwaitExpression(expr) = parent {
if !expr.needs_parentheses(f) {
return write!(f, [group(&indented)]);
}

write!(f, [indented])
} else {
write!(f, [group(&indented)])
};
}

write!(f, [format_inner])
}
}

Expand Down
4 changes: 1 addition & 3 deletions tasks/prettier_conformance/snapshots/prettier.js.snap.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
js compatibility: 525/699 (75.11%)
js compatibility: 527/699 (75.39%)

# Failed

Expand All @@ -10,8 +10,6 @@ js compatibility: 525/699 (75.11%)
| js/arrows/semi/semi.js | 💥✨ | 0.00% |
| js/assignment/issue-10218.js | 💥 | 52.63% |
| js/assignment/sequence.js | 💥 | 71.43% |
| js/async/inline-await.js | 💥 | 25.00% |
| js/async/nested.js | 💥 | 16.67% |
| js/binary-expressions/inline-jsx.js | 💥 | 40.00% |
| js/binary-expressions/jsx_parent.js | 💥 | 33.85% |
| js/binary-expressions/return.js | 💥 | 90.00% |
Expand Down
4 changes: 2 additions & 2 deletions tasks/prettier_conformance/snapshots/prettier.ts.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ts compatibility: 277/573 (48.34%)
| typescript/as/export_default_as.ts | 💥 | 0.00% |
| typescript/as/expression-statement.ts | 💥 | 75.00% |
| typescript/as/long-identifiers.ts | 💥 | 92.86% |
| typescript/as/nested-await-and-as.ts | 💥 | 16.67% |
| typescript/as/nested-await-and-as.ts | 💥 | 42.86% |
| typescript/as/ternary.ts | 💥 | 80.00% |
| typescript/assert/comment.ts | 💥 | 0.00% |
| typescript/assert/index.ts | 💥 | 75.00% |
Expand Down Expand Up @@ -249,7 +249,7 @@ ts compatibility: 277/573 (48.34%)
| typescript/satisfies-operators/expression-statement.ts | 💥💥 | 78.38% |
| typescript/satisfies-operators/gt-lt.ts | 💥💥 | 0.00% |
| typescript/satisfies-operators/lhs.ts | 💥✨ | 30.00% |
| typescript/satisfies-operators/nested-await-and-satisfies.ts | 💥💥 | 16.67% |
| typescript/satisfies-operators/nested-await-and-satisfies.ts | 💥💥 | 42.86% |
| typescript/satisfies-operators/non-null.ts | 💥💥 | 66.67% |
| typescript/satisfies-operators/satisfies.ts | 💥💥 | 68.18% |
| typescript/satisfies-operators/template-literal.ts | 💥💥 | 14.29% |
Expand Down
Loading