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
Optimize jsx spreads of object expressions #12557
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/36464/ |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit d8afcec:
|
The result of spreading an object expression is known at compile time enabling better code generation without a spread or extends helper. Replace convertAttribute function with accumulateAttribute to allow multiple attributes to be created from one input. Rework special case check for spreads when runtime is classic and useSpread is false to rewrite generated props after conversion.
7cfb335
to
49518aa
Compare
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.
Thanks for the PR!
Could you add tests with duplicated props?
<div prop {...{prop}} />;
<div {...{prop}} prop />;
Duplicated keys may be created as per current behaviour, using `@babel/plugin-transform-duplicate-keys` would allow use when transpiling to strict.
@nicolo-ribaudo Added some tests for duplicated props - no change there from current logic with JSX per #2462 so would also want Also changed the 'classic' logic after first push, to be explicitly two-pass which effectively handles the edge cases (and added tests). |
Spurious (probably) failure on
|
I restarted the e2e tests. |
Is there anything I can do to help this get a second review? |
Thanks for the PR! |
Amazing! Thanks all for the reviews. |
The result of spreading an object expression is known at compile time enabling better code generation without a spread or extends helper.
Replace
convertAttribute
function withaccumulateAttribute
to allow multiple attributes to be created from one input.Rework special case check for spreads when runtime is classic and
useSpread
is false to check the last added prop rather than the attribute before conversion.There are edge cases where this will result in vastly smaller code as the helpers which would otherwise be inlined are no longer required. I believe the logic to be sound in all cases, happy to any additional tests that would be helpful.
Generated code differences: