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 656
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rome_js_formatter): Parenthesize Types
This PR implements the rules for when parentheses around TypeScript types are needed or can be removed without changing the semantics of the program. The majority of the PR is to implement `NeedsParentheses` for every `TsType`. This PR further fixes an instability issue with the syntax rewriter. The rewriter used to remove all whitespace between the `(` paren and the token (or first comment and skipped token trivia). This is necessary or the formatter otherwise inserts an extra blank line before nodes that are parenthesized: ``` a ( Long && Longer && ) ``` becomes ``` a ( Long && Longer && ) ``` Notice, the added new line. What this logic didn't account for is that it should not remove a leading new line before a comment because we want to keep the comment on its own line and this requires that there's a leading new line trivia. The last fix is in the source map that so far assumed that all ranges are added in increasing `end` order ``` correct: 2..3, 2..4, 2..5 (notice how the ranges are sorted by end) incorrect: 2..4, 2..3, 2..5 ``` This PR updates the sorting of the text ranges to also account the end ranges. I added unit tests for all rules where parentheses are required and reviewed the updated snapshots. There are a few new changes but these unrelated to parentheses but instead problems with the formatting of the specific syntax. Average compatibility: 83.70 -> 84.11 Compatible lines: 80.79 -> 81.42
- Loading branch information
1 parent
e6730da
commit 9ef7297
Showing
59 changed files
with
1,275 additions
and
1,204 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
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
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
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.