-
-
Notifications
You must be signed in to change notification settings - Fork 849
fix(formatter): preserve parentheses for in expressions in arrow function block bodies
#18352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
| } | ||
|
Comment on lines
+415
to
+418
|
||
|
|
||
| return false; | ||
| } | ||
| // FunctionBody: Continue checking - could be inside arrow function in ForStatement.init | ||
| AstNodes::ForStatement(stmt) => { | ||
|
Comment on lines
+422
to
423
|
||
| return stmt | ||
| .init | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
matches!(stmt.parent, AstNodes::FunctionBody(_))check will be true forExpressionStatements inside any function body (regular functions/methods as well as arrows), not just arrow-function block bodies. If this change is meant to target arrow functions only, consider narrowing the condition to verify the enclosingFunctionBodybelongs to anArrowFunctionExpression(and optionallyarrow.expression == false) to avoid changing parentheses behavior in other function bodies nested underForStatement.init.