Closed
Description
Suggestion
π Search Terms
jsx spread optimization babel
β Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code (not for most of them)
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
β Suggestion
I've noticed that TypeScript emits a different JS output for some cases involving JSXSpreadAttribute
that contains ObjectLiteralExpression
than Babel. It seems that Babel has decided to optimize some of the situations and tries to avoid emitting unnecessary Object.assign
calls/spread assignments.
// input
<Test {...{ foo: "test", bar: 42}} />;
// TS output
React.createElement(Test, Object.assign({}, { foo: "test", bar: 42 }));
// Babel output
React.createElement(Test, { foo: "test", bar: 42 });
So perhaps TS could follow the suite here and avoid this Object.assign
call. This would come with minor bundlesize and perf gains.