Skip to content

Enable regenerator for Hermes dev mode transform profile #52651

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions packages/react-native-babel-preset/src/configs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ const defaultPlugins = [
[require('@babel/plugin-transform-unicode-regex')],
];

// For Static Hermes testing (experimental), the hermes-canary transformProfile
// is used to enable regenerator (and some related lowering passes) because SH
// requires more Babel lowering than Hermes temporarily.
const getPreset = (src, options) => {
const transformProfile =
(options && options.unstable_transformProfile) || 'default';
Expand Down Expand Up @@ -124,8 +121,8 @@ const getPreset = (src, options) => {
extraPlugins.push([
require('@babel/plugin-transform-named-capturing-groups-regex'),
]);
// Needed for regenerator for hermes-canary
if (isHermesCanary) {
// Needed for regenerator
if (isHermes && options.dev) {
extraPlugins.push([
require('@babel/plugin-transform-optional-catch-binding'),
]);
Expand Down Expand Up @@ -158,17 +155,15 @@ const getPreset = (src, options) => {
) {
extraPlugins.push([require('@babel/plugin-transform-react-display-name')]);
}
// Check !isHermesStable because this is needed for regenerator for
// hermes-canary
if (!isHermesStable && (isNull || src.indexOf('?.') !== -1)) {
// Also check options.dev because this is needed for regenerator
if ((!isHermes || options.dev) && (isNull || src.indexOf('?.') !== -1)) {
extraPlugins.push([
require('@babel/plugin-transform-optional-chaining'),
{loose: true},
]);
}
// Check !isHermesStable because this is needed for regenerator for
// hermes-canary
if (!isHermesStable && (isNull || src.indexOf('??') !== -1)) {
// Also check options.dev because this is needed for regenerator
if ((!isHermes || options.dev) && (isNull || src.indexOf('??') !== -1)) {
extraPlugins.push([
require('@babel/plugin-transform-nullish-coalescing-operator'),
{loose: true},
Expand Down Expand Up @@ -196,7 +191,7 @@ const getPreset = (src, options) => {
extraPlugins.push([require('@babel/plugin-transform-react-jsx-self')]);
}

if (isHermesCanary) {
if (isHermes && options.dev) {
const hasForOf =
isNull || (src.indexOf('for') !== -1 && src.indexOf('of') !== -1);
if (hasForOf) {
Expand All @@ -216,11 +211,11 @@ const getPreset = (src, options) => {
require('@babel/plugin-transform-runtime'),
{
helpers: true,
regenerator: !isHermesStable,
regenerator: !isHermes || options.dev,
...(isVersion && {version: options.enableBabelRuntime}),
},
]);
} else if (isHermesCanary) {
} else if (isHermes && options.dev) {
extraPlugins.push([require('@babel/plugin-transform-regenerator')]);
}

Expand Down
Loading