Skip to content
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

Use Object.assign instead of Babel _extends #745

Closed

Conversation

newyankeecodeshop
Copy link
Contributor

Summary

All React Native JavaScript runtimes, as well as Node, implement Object.assign(). This PR removes the transform and configures plugins to use Object.assign instead of injecting the Babel helper _extends(). This simplifies the generated code, and it aligns JavaScriptCore users more closely with Hermes, which doesn't use several of the plugins.

The following plugins generate code using Object.assign directly:

  • transform-destructuring
  • proposal-object-rest-spread
  • transform-react-jsx

Test plan

I added a unit test to verify the new behavior.
The Babel _extends helper already uses Object.assign if it exists, so the runtime behavior will be identical.

_extends = Object.assign || function (target) {
  ...
}

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Nov 29, 2021
Copy link
Contributor

@ericanderson ericanderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@facebook-github-bot
Copy link
Contributor

@rh389 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Feb 11, 2022
Summary:
React Native has an *implicit* dev dependency on this transform via `metro-react-native-babel-transformer`. The transform replaces `Object.assign` with `babelHelpers.extend`, but `Object.assign` has been available natively since node 4.

We intend remove it from metro (facebook/metro#745) as it's no longer needed by any supported runtime - removing RN's small dependency in advance so RN's tests won't break when we do.

Changelog:
[Internal][Changed] - Remove `babel/plugin-transform-object-assign` from jest preprocessor

Reviewed By: motiz88

Differential Revision: D34110208

fbshipit-source-id: 064f8241461fb338de1cd8b53077e8660301aa77
@robhogan
Copy link
Contributor

Thanks again @newyankeecodeshop 👍

@newyankeecodeshop newyankeecodeshop deleted the preset-object-assign branch February 16, 2022 11:59
nevilm-lt pushed a commit to nevilm-lt/metro that referenced this pull request Mar 14, 2022
Summary:
**Summary**

All React Native JavaScript runtimes, as well as Node, implement `Object.assign()`. This PR removes the transform and configures plugins to use `Object.assign` instead of injecting the Babel helper `_extends()`. This simplifies the generated code, and it aligns JavaScriptCore users more closely with Hermes, which doesn't use several of the plugins.

The following plugins generate code using `Object.assign` directly:

- `transform-destructuring`
- `proposal-object-rest-spread`
- `transform-react-jsx`

**Test plan**

I added a unit test to verify the new behavior.
The Babel `_extends` helper already uses Object.assign if it exists, so the runtime behavior will be identical.
```
_extends = Object.assign || function (target) {
  ...
}
```

Pull Request resolved: facebook#745

Reviewed By: motiz88

Differential Revision: D34074342

Pulled By: rh389

fbshipit-source-id: dc416d9b40877da49f6966c5c6708b99fa0ce492
nevilm-lt pushed a commit to nevilm-lt/metro that referenced this pull request Apr 21, 2022
Summary:
**Summary**

All React Native JavaScript runtimes, as well as Node, implement `Object.assign()`. This PR removes the transform and configures plugins to use `Object.assign` instead of injecting the Babel helper `_extends()`. This simplifies the generated code, and it aligns JavaScriptCore users more closely with Hermes, which doesn't use several of the plugins.

The following plugins generate code using `Object.assign` directly:

- `transform-destructuring`
- `proposal-object-rest-spread`
- `transform-react-jsx`

**Test plan**

I added a unit test to verify the new behavior.
The Babel `_extends` helper already uses Object.assign if it exists, so the runtime behavior will be identical.
```
_extends = Object.assign || function (target) {
  ...
}
```

Pull Request resolved: facebook#745

Reviewed By: motiz88

Differential Revision: D34074342

Pulled By: rh389

fbshipit-source-id: dc416d9b40877da49f6966c5c6708b99fa0ce492
nevilm-lt pushed a commit to nevilm-lt/metro that referenced this pull request Apr 22, 2022
Summary:
**Summary**

All React Native JavaScript runtimes, as well as Node, implement `Object.assign()`. This PR removes the transform and configures plugins to use `Object.assign` instead of injecting the Babel helper `_extends()`. This simplifies the generated code, and it aligns JavaScriptCore users more closely with Hermes, which doesn't use several of the plugins.

The following plugins generate code using `Object.assign` directly:

- `transform-destructuring`
- `proposal-object-rest-spread`
- `transform-react-jsx`

**Test plan**

I added a unit test to verify the new behavior.
The Babel `_extends` helper already uses Object.assign if it exists, so the runtime behavior will be identical.
```
_extends = Object.assign || function (target) {
  ...
}
```

Pull Request resolved: facebook#745

Reviewed By: motiz88

Differential Revision: D34074342

Pulled By: rh389

fbshipit-source-id: dc416d9b40877da49f6966c5c6708b99fa0ce492
Saadnajmi pushed a commit to Saadnajmi/react-native-macos that referenced this pull request Jan 15, 2023
Summary:
React Native has an *implicit* dev dependency on this transform via `metro-react-native-babel-transformer`. The transform replaces `Object.assign` with `babelHelpers.extend`, but `Object.assign` has been available natively since node 4.

We intend remove it from metro (facebook/metro#745) as it's no longer needed by any supported runtime - removing RN's small dependency in advance so RN's tests won't break when we do.

Changelog:
[Internal][Changed] - Remove `babel/plugin-transform-object-assign` from jest preprocessor

Reviewed By: motiz88

Differential Revision: D34110208

fbshipit-source-id: 064f8241461fb338de1cd8b53077e8660301aa77
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants