This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 664
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(formatter): Refactor
try_print_flat
to fits_on_line
This PR brings the Printer closer to Prettier's printer by introducing a `fits_on_line` function that measures if printing this element won't exceed the line width. This is somewhat similar to the existing `try_print_flat` implementation but differs in that sense that it also supports measuring content that isn't printed in flat mode. This functionality will be needed to implement alternatives because the alternatives picks the first variant that fits on the line but an alternative itself doesn't have to be printed in flat mode. This PR further introduces the concept of a `GroupId` and adds the ability to use `if_group_breaks` and `if_group_fits_on_line` with a specific group id. This is necessary because this PR aligns the `fill_elements` semantic with Prettier's by introducing an implicit group for each element. The problem of doing this is that the trailing comma insertion no longer worked because the element itself fits on the line (printed in flat mode) but the outer group of the array did break: ``` group([ '[', indent([ soft_line_break(), fill([ [ token('2222222'), if_group_breaks(',') // Doesn't get printed because the element fits ] ]), soft_line_break(), ]) ```
- Loading branch information
1 parent
4f522cd
commit f8ca589
Showing
65 changed files
with
2,066 additions
and
1,284 deletions.
There are no files selected for viewing
This file contains 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
Oops, something went wrong.