Add JSX spread children - #42
Conversation
|
I’m not sure why {
"type": "CommentBlock",
"value": " this is a comment ",
"start": 4,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 27
}
}
}I’m pretty sure it has to do with the Any ideas? |
|
We'll have to hold off on this until it's been specced and added to the react/jsx#57 repo. TypeScript and Flow also support JSX so there's value in having this specced there so they can come into compliance as we add support. |
|
I don't think either TypeScript or Flow support non-React variants of JSX atm so it probably doesn't matter but we can add it. We also don't support namespaces which is speced. |
|
@kittens: The language extension this PR implements was just added to the JSX specification (react/jsx#59). What’s remaining to get this PR merged, and can you comment on the failing test? See my comment above for more details on from the reasons I found that might make it fail. |
|
Just curious @kittens, what’s the status on this? |
| this.next(); | ||
| node.expression = this.parseExpression(); | ||
| this.expect(tt.braceR); | ||
| children.push(this.finishNode(node, "JSXSpreadChild")); |
There was a problem hiding this comment.
JSXSpreadChild would need to be added to babel-types as well and also to babel-generator
There was a problem hiding this comment.
|
Thanks! We can follow up in the Babel PR. |
This PR comes from a conversation in react/jsx#57 where I recommended adding the ability to spread children. For the full rationale see that issue, here’s an abridged version:
JSX with React allows us to do this:
Which translates to this:
That doesn’t make sense and it has disadvantages for simpler JSX consumers as well as type systems. Instead JSX should allow us to do this:
Which would translate to this:
This PR aims to extend JSX by allowing the spreading of children like so:
As another note, it seems like React itself will consider this an anti-pattern. However as JSX is an open standard used by more than just React we should consider the entire ecosystem when considering the merits of this extension. Let’s keep discussion of whether or not the extension should be added to JSX in react/jsx#57 and let’s talk about technical implementations here.
In react/jsx#57 the language extension got a +1 from @syranide (react/jsx#57 (comment)) and @sebmarkbage (react/jsx#57 (comment)).