Skip to content

Optimize JSXSpreadAttribute JS emit when it contains ObjectLiteralExpressionΒ #49099

Closed
@Andarist

Description

@Andarist

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: JSX/TSXRelates to the JSX parser and emitterDomain: PerformanceReports of unusually slow behaviorSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions