fix(js_formatter): Allow function expressions to group and break as call arguments #1003
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Addressing the first case of #914. Playground Link.
This is effectively an extension of #934, utilizing the new
ParameterLayout::Compact
so long ascall_arguments
decides that the expression can be grouped.But, the previous logic only actually formatted as a grouped expression if the function was not the only call argument and had at least one parameter, which was too restrictive. The logic now more closely matches Prettier's logic, using the compact format when the function is not the only call argument or has only simple parameters.
The definition of a simple parameter is somewhat loose, and not an exact match to Prettier, but is close. Prettier says "an identifier with no type annotation", but the semantics of
estree
mean that parameters with an initializer are technicallyAssignment
nodes, while in Biome they are justJsFormalParameter
s with.initializer().is_some()
.Test Plan
Added test cases for the specific grouping behavior, and the prettier diff snapshot for typescript has been removed.