-
Notifications
You must be signed in to change notification settings - Fork 428
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
Parse list and list spread in JSX #1972
base: master
Are you sure you want to change the base?
Conversation
@@ -5637,9 +5637,9 @@ let printer = object(self:'self) | |||
| ({txt="JSX"; loc}, PStr []) :: _ -> | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this has been broken forever 🙈
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.
What's this again?
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.
Printing of fragments. we wanna print the fragment's children before the fragment's siblings.
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.
i.e. depth first vs. breadth first
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I'm not sure. need someone else to weigh in
@@ -270,3 +270,5 @@ let x = foo /></ bar; | |||
<div onClick=this##handleClick> | |||
<> foo bar </> | |||
</div>; | |||
|
|||
<Foo> 1 2 other </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.
Small question, am I wrong that I would expect <Foo> [1, 2] other </Foo>
here?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like @jordwalke's comment (#1429 (comment)) is exactly the behavior that this PR maintains?
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.
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