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
Feat: add jsx spread children support #7294
Conversation
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.
can you add a test to transpiler.test.ts?
also, i wonder if we can detect an array literal spread, to emit |
DONE |
Yes, the optimizer should do this, and actually Bun has already implemented this. // in.js
console.log([...[1, 2, 3]]);
console.log(
jsxDEV(
"div",
{
children: [...[1, 2, 3]],
},
undefined,
true,
undefined,
this,
),
);
console.log(<div>{...[1, 2, 3]}</div>);
// bun-debug build test.js --minify
// ...
console.log([1,2,3]);
console.log(jsxDEV("div",{children:[1,2,3]},void 0,!0,void 0,OJ));
console.log(VJ.jsxDEV("div",{children:[...[1,2,3]]},void 0,!0,void 0,this))})
// ... However, strangely, the code transformed through JSX does not execute this optimization.🤔 If I have time, I will attempt to fix this issue next. |
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 good, i would like to get the unreachable
removed.
these test cases would be nice to have but dont pass right now. i dont really know how hard adding this optimization in would be.
|
I've observed that esbuild also doesn't optimize spread children in jsx, see Implementing this optimization may not be as easy as it seems. I think we should open a new issue to discuss it. |
alright. looks good otherwise. will merge after tests run. |
thank you |
* feat: jsx spread children * test: spread children
What does this PR do?
Example
Output
Before:
After:
This feature is already supported by most transpilers, eg:
Typescript
Esbuild
SWC
How did you verify your code works?
I am willing to add test code for this feature, but I need some help.
As I understand it, the test code should be placed in
test/snippets
,test/snapshots
.However, the
scripts/browser.js
that tests them does not seem to be able to execute properly.