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
feat(rome_js_formatter): Binary expression formatting #3079
Merged
Conversation
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
MichaReiser
force-pushed
the
feat/needs-parentheses
branch
from
August 17, 2022 16:27
1740c40
to
6293638
Compare
MichaReiser
force-pushed
the
feat/binary-expressions
branch
from
August 17, 2022 16:30
d7a1a9b
to
c0de7df
Compare
Deploying with Cloudflare Pages
|
MichaReiser
force-pushed
the
feat/needs-parentheses
branch
from
August 18, 2022 07:21
9823c4b
to
e896925
Compare
MichaReiser
force-pushed
the
feat/binary-expressions
branch
from
August 18, 2022 07:34
c0de7df
to
d5de48c
Compare
What does "re-balance a tree" mean? |
To change the tree's shape without changing the semantic meaning. In this particular case, it means that a tree that has nested logical expressions in the right side to the left side so that the right side.
The transformed version works well with our flattening logic where it will miss the former completely. |
MichaReiser
force-pushed
the
feat/binary-expressions
branch
from
August 18, 2022 12:20
c84eca0
to
db28af0
Compare
ematipico
approved these changes
Aug 18, 2022
IWANABETHATGUY
pushed a commit
to IWANABETHATGUY/tools
that referenced
this pull request
Aug 22, 2022
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
Part of #3046
This PR refactors our
JsAnyBinaryLikeExpression
formatting to closer match prettier's formatting. The main change is that our old implementation used to group the operator with the left hand side:became
whereas prettier (and this PR) always groups the operator with the right-hand side
This PR further enables the
NeedsParentheses
implementation for binary expressions.Unsupported case
The new implementation doesn't support the
issue-7024
test caseThe issue is that removing the parentheses from
((!isAnyValueSelected && values[a].default === true) || a === 0)
rebalances the tree. Prettier solves this problem by rebalancing logical expressions ahead of formatting. This is something Rome doesn't support today which is why I disabled parentheses removal from logical expression if the child and parent have the same operator but the child is the right side expression.Test Plan
I manually reviewed the snapshot changes.
Average compatibility: 81.64 -> 82.59
Compatible lines: 78.42 -> 79.70