Skip to content

Object spread operator is unnecessarily transformed when used with React #7044

Description

@spmonahan

Describe the bug

When spreading props onto a React component object literal spread is converted to Object.assign despite all target browsers natively supporting object literal spread according to caniuse.

Input code

const Component = (props) => {
    return <div {...props}/>
}

const obj = { a: 1, b: 2};
// This is transformed to Object.assign
<Component {...obj}/>

// This is not transformed
const clone = { ...obj };

Config

{
  "$schema": "https://json.schemastore.org/swcrc",
  "env": {
    "targets": {
      "chrome": "84",
      "edge": "84",
      "firefox": "75",
      "opera": "73",
      "safari": "14.1"
    },
    "bugfixes": true
  },
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true,
      "decorators": false,
      "dynamicImport": false
    },
    "externalHelpers": true,
    "transform": {
      "react": {
        "useBuiltins": true
      }
    },
    "target": "es2019"
  },
  "minify": false,
  "sourceMaps": true
}

Playground link

https://play.swc.rs/?version=1.3.36&code=H4sIAAAAAAAAA1WOQQ6CMBBF9016h7%2FUxJToEoENB3DjBaBUhcgMaUc3hLtbaow6meW898YyBUHN48TkSFBiM3mewhZlhVkrxPFOHp5QdP0TszEmHSxZpdWilVY2KbgdIjyjybHfoc1xWI5aZRnOtz4grviGwoX96DoI49QOzoppQuivpFXxfWFNRFsK%2FBmI5dfyKdt75FL7DWINvwC%2FeYK%2B2AAAAA%3D%3D&config=H4sIAAAAAAAAAz2QS27DMAxE7yJ0adh1kyKtl1m1ixyCVShbgfUBSbU2gt69FFxnNzMCH4e6mye2EwYwg5lEMg9dd%2BMU2y1lSYRtorHjH0vWNAbjtxnuRoBGFK7STpQC6vzbsb5fx4d2ntClRe3pVW3KSHXP6aCGwQF5df2x7c1vY77K6PyCihQqqMGNbcVnIEaqitcoUGmyZmRLPouChJdtpDFXtIlAKyvEwcw1WiMEbz9DTiT%2FqbJxEaQI8wfOWop3gBBEdolCXUcIVqoojOfiZ%2FFxL6eE7QO0DPLLc%2F9eLwg%2Berc%2BVnMqZPECeZ%2F6A0dP8b5sAQAA

Expected behavior

I expect that object literal spread should not be converted to Object.assign when used with React components with the provided config.

Actual behavior

Object literal spread on React components is converted to Object.assign but usage outside of React is not converted.

Version

1.3.36

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions