Parse list and list spread in JSX#1972
Conversation
| begin match self#simplest_expression x with | ||
| | Some r -> self#formatChildren remaining (r :: processedRev) | ||
| | None -> self#formatChildren (remaining @ children) processedRev | ||
| | None -> self#formatChildren (children @ remaining) processedRev |
There was a problem hiding this comment.
this has been broken forever 🙈
There was a problem hiding this comment.
Printing of fragments. we wanna print the fragment's children before the fragment's siblings.
There was a problem hiding this comment.
i.e. depth first vs. breadth first
There was a problem hiding this comment.
this test:
<div> <> ...[ [1,2], [3,4] ] </> </div>was getting formatted to
<div> <> 1 3 2 4 </> </div>i.e. 1 3 2 4 instead of 1 2 3 4 :)
There was a problem hiding this comment.
Same question as above, I think I expect <div> <> [1,2] [3,4] </> </div> here. Am I wrong?
There was a problem hiding this comment.
yeah, I'm not sure. need someone else to weigh in
| <> foo bar </> | ||
| </div>; | ||
|
|
||
| <Foo> 1 2 other </Foo>; |
There was a problem hiding this comment.
Small question, am I wrong that I would expect <Foo> [1, 2] other </Foo> here?
There was a problem hiding this comment.
yeah I'm not sure about this one. it currently looks to me that lists are always spliced in
There was a problem hiding this comment.
We should not eagerly cancel out list spread + list wrapping at a syntax level, since there might be ppxes that turns the list literal into something else (e.g. react jsx ppx turns children list into array. So <Foo> ...[] </Foo> should stay as such after formatting. Though I recall the implementation for keeping it like that becomes complicated?
There was a problem hiding this comment.
that isn't the case in master however. this is the current behavior:
$ echo '<div> ...[] </div>' | refmt
<div />;
There was a problem hiding this comment.
Back in the days, we decided to delay the problem because of non-idempotent formatting and possible problems with the react jsx ppx (fortunately nobody uses spread lists).
See #1429 for background
There was a problem hiding this comment.
Looks like @jordwalke's comment (#1429 (comment)) is exactly the behavior that this PR maintains?
There was a problem hiding this comment.
Yes, I think with the current infrastructure that this is the only thing we can do.
The only thing that I can think of is the <div> ...[ [1,2], [3, 4] ]</div>. If I'm interpreting that comment right, that should format to <div> [1, 2] [3, 4] </div>
aeebd5a to
9d77da3
Compare
9d77da3 to
0217c11
Compare
0217c11 to
3bc3f91
Compare
|
To try to invalidate the above, I can do Am I making sense? Essentially, it should always be the case that whichever spread you use with whichever fragment syntax, and whichever composition of those, can always be distinguished when the PPX goes through the AST. We shouldn't accidentally lose info from our syntax-level eager removal of |
|
I rebased and fixed quite a few things in master...Drup:jsxlist In particular, inline lists and normal elements can now be interleaved: The printer is still completely incorrect, I haven't fixed it yet (and my motivation is wearing a bit thin :p). |
fixes #1467