diff --git a/crates/oxc_formatter/src/parentheses/expression.rs b/crates/oxc_formatter/src/parentheses/expression.rs index 6266895c58aff..63dde209c5cb3 100644 --- a/crates/oxc_formatter/src/parentheses/expression.rs +++ b/crates/oxc_formatter/src/parentheses/expression.rs @@ -406,14 +406,20 @@ fn is_in_for_initializer(expr: &AstNode<'_, BinaryExpression<'_>>) -> bool { match parent { AstNodes::ExpressionStatement(stmt) => { if stmt.is_arrow_function_body() { + // Expression body: `() => expr` // Skip `FunctionBody` and `ArrowFunctionExpression` let skipped = ancestors.by_ref().nth(1); debug_assert!(matches!(skipped, Some(AstNodes::ArrowFunctionExpression(_)))); continue; } + // Block body: `() => { expr; }` - check if we're inside a FunctionBody + if matches!(stmt.parent, AstNodes::FunctionBody(_)) { + continue; + } return false; } + // FunctionBody: Continue checking - could be inside arrow function in ForStatement.init AstNodes::ForStatement(stmt) => { return stmt .init diff --git a/tasks/prettier_conformance/snapshots/prettier.js.snap.md b/tasks/prettier_conformance/snapshots/prettier.js.snap.md index 698346155e86c..647cd505d1504 100644 --- a/tasks/prettier_conformance/snapshots/prettier.js.snap.md +++ b/tasks/prettier_conformance/snapshots/prettier.js.snap.md @@ -1,4 +1,4 @@ -js compatibility: 737/754 (97.75%) +js compatibility: 738/754 (97.88%) # Failed @@ -11,8 +11,7 @@ js compatibility: 737/754 (97.75%) | js/comments/return-statement.js | 💥💥 | 98.85% | | js/explicit-resource-management/valid-await-using-comments.js | 💥 | 80.00% | | js/for/9812-unstable.js | 💥 | 63.64% | -| js/for/for-in-with-initializer.js | 💥 | 37.50% | -| js/for/parentheses.js | 💥 | 97.96% | +| js/for/for-in-with-initializer.js | 💥 | 31.25% | | js/last-argument-expansion/dangling-comment-in-arrow-function.js | 💥 | 22.22% | | js/quote-props/objects.js | 💥💥✨✨ | 48.04% | | js/quote-props/with_numbers.js | 💥💥✨✨ | 46.43% |