Skip to content

Commit ac5957d

Browse files
robhoganfacebook-github-bot
authored andcommitted
Align default transform profile Babel preset with legacy Hermes - drop "older" engines (#54806)
Summary: Align the default transform profile in our Babel preset with the current state of `hermes-stable`, drop non-Hermes, pre-ES6 engines which have been unsupported in core since the JSC removal. This will allow us to subsequently repurpose transform profiles (`unstable_transformProfile`) to remove transforms unnecessary for Hermes v1 (aka Static Hermes) as follows: - `hermes-canary` -> Hermes v1 (experimental features) - `hermes-stable` -> Hermes v1 - Default -> All supported engines (i.e, Hermes v1 and legacy) Changelog: [General][Removed] Remove Babel preset transforms for already-unsupported non-Hermes engines Reviewed By: javache, huntie Differential Revision: D88269506
1 parent 602a2d2 commit ac5957d

File tree

4 files changed

+36
-87
lines changed

4 files changed

+36
-87
lines changed

packages/react-native-babel-preset/package.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,19 @@
3131
"@babel/plugin-syntax-export-default-from": "^7.24.7",
3232
"@babel/plugin-syntax-nullish-coalescing-operator": "^7.8.3",
3333
"@babel/plugin-syntax-optional-chaining": "^7.8.3",
34-
"@babel/plugin-transform-arrow-functions": "^7.24.7",
3534
"@babel/plugin-transform-async-generator-functions": "^7.25.4",
3635
"@babel/plugin-transform-async-to-generator": "^7.24.7",
3736
"@babel/plugin-transform-block-scoping": "^7.25.0",
3837
"@babel/plugin-transform-class-properties": "^7.25.4",
3938
"@babel/plugin-transform-classes": "^7.25.4",
40-
"@babel/plugin-transform-computed-properties": "^7.24.7",
4139
"@babel/plugin-transform-destructuring": "^7.24.8",
4240
"@babel/plugin-transform-flow-strip-types": "^7.25.2",
4341
"@babel/plugin-transform-for-of": "^7.24.7",
44-
"@babel/plugin-transform-function-name": "^7.25.1",
45-
"@babel/plugin-transform-literals": "^7.25.2",
46-
"@babel/plugin-transform-logical-assignment-operators": "^7.24.7",
4742
"@babel/plugin-transform-modules-commonjs": "^7.24.8",
4843
"@babel/plugin-transform-named-capturing-groups-regex": "^7.24.7",
4944
"@babel/plugin-transform-nullish-coalescing-operator": "^7.24.7",
50-
"@babel/plugin-transform-numeric-separator": "^7.24.7",
51-
"@babel/plugin-transform-object-rest-spread": "^7.24.7",
5245
"@babel/plugin-transform-optional-catch-binding": "^7.24.7",
5346
"@babel/plugin-transform-optional-chaining": "^7.24.8",
54-
"@babel/plugin-transform-parameters": "^7.24.7",
5547
"@babel/plugin-transform-private-methods": "^7.24.7",
5648
"@babel/plugin-transform-private-property-in-object": "^7.24.7",
5749
"@babel/plugin-transform-react-display-name": "^7.24.7",
@@ -60,12 +52,8 @@
6052
"@babel/plugin-transform-react-jsx-source": "^7.24.7",
6153
"@babel/plugin-transform-regenerator": "^7.24.7",
6254
"@babel/plugin-transform-runtime": "^7.24.7",
63-
"@babel/plugin-transform-shorthand-properties": "^7.24.7",
64-
"@babel/plugin-transform-spread": "^7.24.7",
65-
"@babel/plugin-transform-sticky-regex": "^7.24.7",
6655
"@babel/plugin-transform-typescript": "^7.25.2",
6756
"@babel/plugin-transform-unicode-regex": "^7.24.7",
68-
"@babel/template": "^7.25.0",
6957
"@react-native/babel-plugin-codegen": "0.84.0-main",
7058
"babel-plugin-syntax-hermes-parser": "0.32.0",
7159
"babel-plugin-transform-flow-enums": "^0.0.2",

packages/react-native-babel-preset/src/configs/main.js

Lines changed: 25 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ const getPreset = (src, options) => {
4949
const isHermesCanary = transformProfile === 'hermes-canary';
5050
const isHermes = isHermesStable || isHermesCanary;
5151

52-
// We enable regenerator for !isHermes. Additionally, in dev mode we also
53-
// enable regenerator for the time being because Static Hermes doesn't yet
54-
// support debugging native generators. However, some apps have native
55-
// generators in release mode because it has already yielded perf wins. The
56-
// next release of Static Hermes will close this gap, so this won't be
57-
// permanent.
58-
const enableRegenerator = !isHermes || options.dev;
52+
// We enable regenerator in dev builds for the time being because
53+
// Static Hermes doesn't yet fully support debugging native generators.
54+
// (e.g. - it's not possible to inspect local variables when paused in a
55+
// generator).
56+
//
57+
// Use native generators in release mode because it has already yielded perf
58+
// wins. The next release of Static Hermes will close this gap, so this won't
59+
// be permanent.
60+
const enableRegenerator = isHermes && options.dev;
5961

6062
const isNull = src == null;
6163
const hasClass = isNull || src.indexOf('class') !== -1;
@@ -102,48 +104,20 @@ const getPreset = (src, options) => {
102104
extraPlugins.push([require('@babel/plugin-transform-classes')]);
103105
}
104106

105-
if (!isHermes && (isNull || src.includes('=>'))) {
106-
extraPlugins.push([require('@babel/plugin-transform-arrow-functions')]);
107-
}
108-
109-
if (!isHermes) {
110-
extraPlugins.push([require('@babel/plugin-transform-computed-properties')]);
111-
extraPlugins.push([require('@babel/plugin-transform-parameters')]);
112-
extraPlugins.push([
113-
require('@babel/plugin-transform-shorthand-properties'),
114-
]);
107+
extraPlugins.push([
108+
require('@babel/plugin-transform-named-capturing-groups-regex'),
109+
]);
110+
// Needed for regenerator
111+
if (enableRegenerator) {
115112
extraPlugins.push([
116113
require('@babel/plugin-transform-optional-catch-binding'),
117114
]);
118-
extraPlugins.push([require('@babel/plugin-transform-function-name')]);
119-
extraPlugins.push([require('@babel/plugin-transform-literals')]);
120-
extraPlugins.push([require('@babel/plugin-transform-numeric-separator')]);
121-
extraPlugins.push([require('@babel/plugin-transform-sticky-regex')]);
122-
} else {
123-
extraPlugins.push([
124-
require('@babel/plugin-transform-named-capturing-groups-regex'),
125-
]);
126-
// Needed for regenerator
127-
if (isHermes && enableRegenerator) {
128-
extraPlugins.push([
129-
require('@babel/plugin-transform-optional-catch-binding'),
130-
]);
131-
}
132115
}
116+
133117
extraPlugins.push([
134118
require('@babel/plugin-transform-destructuring'),
135119
{useBuiltIns: true},
136120
]);
137-
if (!isHermes && (isNull || hasClass || src.indexOf('...') !== -1)) {
138-
extraPlugins.push(
139-
[require('@babel/plugin-transform-spread')],
140-
[
141-
require('@babel/plugin-transform-object-rest-spread'),
142-
// Assume no dependence on getters or evaluation order. See https://github.com/babel/babel/pull/11520
143-
{loose: true, useBuiltIns: true},
144-
],
145-
);
146-
}
147121
if (isNull || src.indexOf('async') !== -1) {
148122
extraPlugins.push([
149123
require('@babel/plugin-transform-async-generator-functions'),
@@ -171,18 +145,6 @@ const getPreset = (src, options) => {
171145
{loose: true},
172146
]);
173147
}
174-
if (
175-
!isHermes &&
176-
(isNull ||
177-
src.indexOf('??=') !== -1 ||
178-
src.indexOf('||=') !== -1 ||
179-
src.indexOf('&&=') !== -1)
180-
) {
181-
extraPlugins.push([
182-
require('@babel/plugin-transform-logical-assignment-operators'),
183-
{loose: true},
184-
]);
185-
}
186148

187149
if (options && options.dev && !options.disableDeepImportWarnings) {
188150
firstPartyPlugins.push([require('../plugin-warn-on-deep-imports.js')]);
@@ -193,16 +155,15 @@ const getPreset = (src, options) => {
193155
extraPlugins.push([require('@babel/plugin-transform-react-jsx-self')]);
194156
}
195157

196-
if (isHermes && enableRegenerator) {
197-
const hasForOf =
198-
isNull || (src.indexOf('for') !== -1 && src.indexOf('of') !== -1);
199-
if (hasForOf) {
200-
// Needed for regenerator
201-
extraPlugins.push([
202-
require('@babel/plugin-transform-for-of'),
203-
{loose: true},
204-
]);
205-
}
158+
if (
159+
enableRegenerator &&
160+
(isNull || (src.indexOf('for') !== -1 && src.indexOf('of') !== -1))
161+
) {
162+
// Needed for regenerator
163+
extraPlugins.push([
164+
require('@babel/plugin-transform-for-of'),
165+
{loose: true},
166+
]);
206167
}
207168

208169
if (!options || options.enableBabelRuntime !== false) {
@@ -217,7 +178,7 @@ const getPreset = (src, options) => {
217178
...(isVersion && {version: options.enableBabelRuntime}),
218179
},
219180
]);
220-
} else if (isHermes && enableRegenerator) {
181+
} else if (enableRegenerator) {
221182
extraPlugins.push([require('@babel/plugin-transform-regenerator')]);
222183
}
223184

packages/react-native/jest/mockComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default function mockComponent<
3939

4040
const SuperClass: typeof React.Component<{...}> =
4141
typeof RealComponent === 'function' &&
42-
RealComponent.prototype.constructor instanceof React.Component
42+
RealComponent.prototype?.constructor instanceof React.Component
4343
? RealComponent
4444
: React.Component;
4545

yarn.lock

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@
462462
"@babel/helper-create-regexp-features-plugin" "^7.18.6"
463463
"@babel/helper-plugin-utils" "^7.18.6"
464464

465-
"@babel/plugin-transform-arrow-functions@^7.24.7", "@babel/plugin-transform-arrow-functions@^7.25.9":
465+
"@babel/plugin-transform-arrow-functions@^7.25.9":
466466
version "7.25.9"
467467
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.25.9.tgz#7821d4410bee5daaadbb4cdd9a6649704e176845"
468468
integrity sha512-6jmooXYIwn9ca5/RylZADJ+EnSxVUS5sjeJ9UPk6RWRzXCmOJCy6dqItPJFpw2cuCangPK4OYr5uhGKcmrm5Qg==
@@ -529,7 +529,7 @@
529529
"@babel/traverse" "^7.25.9"
530530
globals "^11.1.0"
531531

532-
"@babel/plugin-transform-computed-properties@^7.24.7", "@babel/plugin-transform-computed-properties@^7.25.9":
532+
"@babel/plugin-transform-computed-properties@^7.25.9":
533533
version "7.25.9"
534534
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-computed-properties/-/plugin-transform-computed-properties-7.25.9.tgz#db36492c78460e534b8852b1d5befe3c923ef10b"
535535
integrity sha512-HnBegGqXZR12xbcTHlJ9HGxw1OniltT26J5YpfruGqtUHlz/xKf/G2ak9e+t0rVqrjXa9WOhvYPz1ERfMj23AA==
@@ -604,7 +604,7 @@
604604
"@babel/helper-plugin-utils" "^7.26.5"
605605
"@babel/helper-skip-transparent-expression-wrappers" "^7.25.9"
606606

607-
"@babel/plugin-transform-function-name@^7.25.1", "@babel/plugin-transform-function-name@^7.25.9":
607+
"@babel/plugin-transform-function-name@^7.25.9":
608608
version "7.25.9"
609609
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-function-name/-/plugin-transform-function-name-7.25.9.tgz#939d956e68a606661005bfd550c4fc2ef95f7b97"
610610
integrity sha512-8lP+Yxjv14Vc5MuWBpJsoUCd3hD6V9DgBon2FVYL4jJgbnVQ9fTgYmonchzZJOVNgzEgbxp4OwAf6xz6M/14XA==
@@ -620,14 +620,14 @@
620620
dependencies:
621621
"@babel/helper-plugin-utils" "^7.25.9"
622622

623-
"@babel/plugin-transform-literals@^7.25.2", "@babel/plugin-transform-literals@^7.25.9":
623+
"@babel/plugin-transform-literals@^7.25.9":
624624
version "7.25.9"
625625
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-literals/-/plugin-transform-literals-7.25.9.tgz#1a1c6b4d4aa59bc4cad5b6b3a223a0abd685c9de"
626626
integrity sha512-9N7+2lFziW8W9pBl2TzaNht3+pgMIRP74zizeCSrtnSKVdUl8mAjjOP2OOVQAfZ881P2cNjDj1uAMEdeD50nuQ==
627627
dependencies:
628628
"@babel/helper-plugin-utils" "^7.25.9"
629629

630-
"@babel/plugin-transform-logical-assignment-operators@^7.24.7", "@babel/plugin-transform-logical-assignment-operators@^7.25.9":
630+
"@babel/plugin-transform-logical-assignment-operators@^7.25.9":
631631
version "7.25.9"
632632
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-logical-assignment-operators/-/plugin-transform-logical-assignment-operators-7.25.9.tgz#b19441a8c39a2fda0902900b306ea05ae1055db7"
633633
integrity sha512-wI4wRAzGko551Y8eVf6iOY9EouIDTtPb0ByZx+ktDGHwv6bHFimrgJM/2T021txPZ2s4c7bqvHbd+vXG6K948Q==
@@ -697,7 +697,7 @@
697697
dependencies:
698698
"@babel/helper-plugin-utils" "^7.26.5"
699699

700-
"@babel/plugin-transform-numeric-separator@^7.24.7", "@babel/plugin-transform-numeric-separator@^7.25.9":
700+
"@babel/plugin-transform-numeric-separator@^7.25.9":
701701
version "7.25.9"
702702
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-numeric-separator/-/plugin-transform-numeric-separator-7.25.9.tgz#bfed75866261a8b643468b0ccfd275f2033214a1"
703703
integrity sha512-TlprrJ1GBZ3r6s96Yq8gEQv82s8/5HnCVHtEJScUj90thHQbwe+E5MLhi2bbNHBEJuzrvltXSru+BUxHDoog7Q==
@@ -736,7 +736,7 @@
736736
"@babel/helper-plugin-utils" "^7.25.9"
737737
"@babel/helper-skip-transparent-expression-wrappers" "^7.25.9"
738738

739-
"@babel/plugin-transform-parameters@^7.24.7", "@babel/plugin-transform-parameters@^7.25.9":
739+
"@babel/plugin-transform-parameters@^7.25.9":
740740
version "7.25.9"
741741
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-parameters/-/plugin-transform-parameters-7.25.9.tgz#b856842205b3e77e18b7a7a1b94958069c7ba257"
742742
integrity sha512-wzz6MKwpnshBAiRmn4jR8LYz/g8Ksg0o80XmwZDlordjwEk9SxBzTWC7F5ef1jhbrbOW2DJ5J6ayRukrJmnr0g==
@@ -834,22 +834,22 @@
834834
babel-plugin-polyfill-regenerator "^0.6.1"
835835
semver "^6.3.1"
836836

837-
"@babel/plugin-transform-shorthand-properties@^7.24.7", "@babel/plugin-transform-shorthand-properties@^7.25.9":
837+
"@babel/plugin-transform-shorthand-properties@^7.25.9":
838838
version "7.25.9"
839839
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.25.9.tgz#bb785e6091f99f826a95f9894fc16fde61c163f2"
840840
integrity sha512-MUv6t0FhO5qHnS/W8XCbHmiRWOphNufpE1IVxhK5kuN3Td9FT1x4rx4K42s3RYdMXCXpfWkGSbCSd0Z64xA7Ng==
841841
dependencies:
842842
"@babel/helper-plugin-utils" "^7.25.9"
843843

844-
"@babel/plugin-transform-spread@^7.24.7", "@babel/plugin-transform-spread@^7.25.9":
844+
"@babel/plugin-transform-spread@^7.25.9":
845845
version "7.25.9"
846846
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-spread/-/plugin-transform-spread-7.25.9.tgz#24a35153931b4ba3d13cec4a7748c21ab5514ef9"
847847
integrity sha512-oNknIB0TbURU5pqJFVbOOFspVlrpVwo2H1+HUIsVDvp5VauGGDP1ZEvO8Nn5xyMEs3dakajOxlmkNW7kNgSm6A==
848848
dependencies:
849849
"@babel/helper-plugin-utils" "^7.25.9"
850850
"@babel/helper-skip-transparent-expression-wrappers" "^7.25.9"
851851

852-
"@babel/plugin-transform-sticky-regex@^7.24.7", "@babel/plugin-transform-sticky-regex@^7.25.9":
852+
"@babel/plugin-transform-sticky-regex@^7.25.9":
853853
version "7.25.9"
854854
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-sticky-regex/-/plugin-transform-sticky-regex-7.25.9.tgz#c7f02b944e986a417817b20ba2c504dfc1453d32"
855855
integrity sha512-WqBUSgeVwucYDP9U/xNRQam7xV8W5Zf+6Eo7T2SRVUFlhRiMNFdFz58u0KZmCVVqs2i7SHgpRnAhzRNmKfi2uA==

0 commit comments

Comments
 (0)