-
Notifications
You must be signed in to change notification settings - Fork 38
Fix the usage of spreadProps without any other props #645
Conversation
mununki
commented
Sep 20, 2022
•
edited
Loading
edited
tests/ppx/react/spreadProps.res
Outdated
let c0 = <A x="x" {...p} /> | ||
|
||
// ignore second one | ||
let c0 = <A x="x" {...p0} {...p1} /> |
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.
Shouldn't this be an error?
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 would be more nicer, because the second p1
would be ignored anyway.
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.
let c1 = <A {...p} /> | ||
|
||
// reversed order | ||
let c2 = <A {...p} x="x" /> |
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.
Looking at the generated output, perhaps this should also be the only order allowed, and the first example, in the other order, should be an error?
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 think we need to describe the spec of how the spread props will work compared to the js. In js, always the latter one has a priority which means order does matter. But in v4 spread props, independent props always have a priority.
How about allowing reversed order only? The semantic seems matching to the js output.
let c2 = <A {...p} x="x" />
Or, describing on the spec that each independent prop will be updated at the end regardless of order.
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.
Exactly. Allowing reverse only seems natural. And avoids confusion if there's only one way.
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.
One thing came to my mind, maybe I think I can extract the (label, expression) list from arguments and label declaration in spread prop. then I can reduce it to the single record expression. I’ll give it a try.
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.
Ah..I confused. Never mind the reduce thing, p
is a just Lident not Pexp_record.
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.
- first in order - multiple use not allowed
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 is great.
Just added a couple of suggestions to make the error message easier to understand.
Other than that, ready to go.