Skip to content

Commit

Permalink
Apply Babel arrow transform only when needed (#41253)
Browse files Browse the repository at this point in the history
Summary:
Hermes supports arrows. I assume the only reason the transform wasn't dropped is due to the scary TODO.

Originally, the arrow transform was conditional like this:

```js
  if (isNull || src.indexOf('=>') !== -1) {
    extraPlugins.push(es2015ArrowFunctions);
  }
```

I made it unconditional in facebook/metro@beb3d1a (D15947985) to work around an issue where React Refresh Babel plugin emitted arrow functions. However, I fixed that plugin to _not_ emit arrow functions a long time ago in facebook/react#15956. So this TODO is effectively solved, and has been, for ages.

In this commit, we:

- Skip the transform for Hermes altogether
- For non-Hermes, revert to the old conditional behavior

Possible alternatives:

- We could skip it for Hermes but apply unconditionally otherwise (a bit simpler)
- Or, if all target non-Hermes runtimes already support it natively, we could completely remove it

## Changelog:

[GENERAL] [CHANGED] - Apply Babel arrow transform only on non-Hermes

Pull Request resolved: #41253

Test Plan: Run fbsource tests (that's for you, not for me :)

Reviewed By: NickGerleman

Differential Revision: D50818568

Pulled By: robhogan

fbshipit-source-id: ad96540bb7778792d38a6ddec06999d2acf620d0
  • Loading branch information
gaearon authored and facebook-github-bot committed Oct 31, 2023
1 parent a337f6e commit 9a3b75c
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/react-native-babel-preset/src/configs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ const getPreset = (src, options) => {
extraPlugins.push([require('@babel/plugin-transform-classes')]);
}

// TODO(gaearon): put this back into '=>' indexOf bailout
// and patch react-refresh to not depend on this transform.
extraPlugins.push([require('@babel/plugin-transform-arrow-functions')]);

if (!isHermes && (isNull || src.indexOf('=>') !== -1)) {
extraPlugins.push([require('@babel/plugin-transform-arrow-functions')]);
}
if (!isHermes) {
extraPlugins.push([require('@babel/plugin-transform-computed-properties')]);
extraPlugins.push([require('@babel/plugin-transform-parameters')]);
Expand Down

0 comments on commit 9a3b75c

Please sign in to comment.