New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent JSX from breaking a logical expression chain #5092
Conversation
@@ -823,8 +823,7 @@ exports[`logical-expression.js - flow-verify 1`] = ` | |||
</div>; | |||
|
|||
<div> | |||
{a && | |||
b && ( | |||
{a && b && ( | |||
<span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This indentation level looks too deep
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I missed that
I don't think there's a way to solve this without a new primitive, or using different (but worse IMO) heuristics.. What I'm currently doing is: if the last member is JSX, split in two groups: one for the JSX and another for everything else. In that case, we can either have (first uses {a && b && (
<Foo />
)}
{a &&
b && (
<Foo />
)} versus: {a && b && (
<Foo />
)}
{a &&
b && (
<Foo />
)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requesting changes for clarification because the indentation level issue is a blocker
@duailibe I think we could solve it by checking if the last thing in the ternary chain is JSX when we print every ternary child, but it's duplicative work (from each child, walk up to the parent, then walk back down to check if the chain's last child is JSX). I guess we could use some kind of cache if we wanted to reduce the scope, but it'd be nice to have a primitive that works like React context for this particular use-case; something like (pseudocode):
|
The idea being that every doc node in the tree could use context("foo",
context("bar",
group(...)
)
) Inside the group, context is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woo!
Closes #5089
Maybe we want to think about doing the same for objects and arrays