Repository navigation
fix: break up an array that's the body of an assigned arrow function instead of moving the arrow function to the next line - #912
Merged
Conversation
…instead of moving the arrow function to the next line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes output that changed when formatted a second time. At
lineWidth: 40:was formatted as:
and formatting that again gave:
The arrow function's expression body is in a new line group, so when the array didn't fit, the arrow function was moved to the line after the
=before the array was broken up. The array then keeps its line breaks, so the next timeconst f = () => [fits on the first line. Now the array is broken up in place the first time, the same asconst f = [...],const f = () => ({...})and a block body. This applies to everything that's generated as an assignment (declarators, assignments, properties, default values), including curried arrow functions.It's not done when
arrayExpression.preferSingleLineistrueor the array prefers hanging, because those arrays don't keep their line breaks.Changes to output that was stable
An array that fits on the line after the
=is now broken up in place:becomes
const f = () => [with an element per line.The array is broken up before the parameters:
const f = (\n a,\n b,\n) => [...]becomesconst f = (a, b) => [with the array expanded.When the code up to the
[doesn't fit on the line of the=, the arrow function still moves to the next line.