Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Fix the usage of spreadProps without any other props #645

Merged
merged 5 commits into from
Sep 22, 2022

Conversation

mununki
Copy link
Member

@mununki mununki commented Sep 20, 2022

// original
let c1 = <A {...p} />

// converted to
// v4 classic
let c1 = React.createElement(A.make, p)

// v4 automatic
let c1 = React.jsx(A.make, p)

let c0 = <A x="x" {...p} />

// ignore second one
let c0 = <A x="x" {...p0} {...p1} />
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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" />
Copy link
Contributor

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?

Copy link
Member Author

@mununki mununki Sep 20, 2022

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.

Copy link
Contributor

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.

Copy link
Member Author

@mununki mununki Sep 20, 2022

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.

Copy link
Member Author

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.

Copy link
Member Author

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
Copy link
Contributor

@cristianoc cristianoc left a 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.

@cristianoc cristianoc merged commit 307b35c into master Sep 22, 2022
@mununki mununki deleted the fix-spread-props-only branch September 22, 2022 10:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants