Skip to content

Commit f654168

Browse files
robhoganmeta-codesync[bot]
authored andcommitted
Disable JS class transforms for Hermes V1 (use SH-native class support) (#55039)
Summary: Pull Request resolved: #55039 When `unstable_transformProfile` (either the preset option or via `caller` from Metro) is set to `'hermes-stable'` or `'hermes-canary'`, infer that the target engine is Hermes V1. For Hermes V1, we don't need to transform `class` syntax any more - this has been proven in production experiments. This should improve the performance of class-intensive APIs, like `Animated`, reduce bundle size, and improve bundling times. Changelog: [Internal] Disable JS class transform behind unstable_transformProfile=hermes-stable Reviewed By: javache, huntie Differential Revision: D89724839 fbshipit-source-id: c25d0080ddac19cc5a746b8d423e091a05df88a3
1 parent 4bd62a1 commit f654168

File tree

1 file changed

+12
-13
lines changed
  • packages/react-native-babel-preset/src/configs

1 file changed

+12
-13
lines changed

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ const EXCLUDED_FIRST_PARTY_PATHS = [
2020
/[/\\]private[/\\]react-native-fantom[/\\]/,
2121
];
2222

23-
// customTransformOptions may be strings from URL params, or booleans passed
24-
// programatically. For strings, handle them as Metro does when parsing URLs.
25-
const TRUE_VALS = new Set([true, 'true', '1']);
26-
2723
function isTypeScriptSource(fileName) {
2824
return !!fileName && fileName.endsWith('.ts');
2925
}
@@ -54,25 +50,28 @@ const getPreset = (src, options, babel) => {
5450
const transformProfile =
5551
options?.unstable_transformProfile ?? babel?.caller(getTransformProfile);
5652

57-
const isHermesStable = transformProfile === 'hermes-stable';
58-
const isHermesCanary = transformProfile === 'hermes-canary';
59-
const isHermes = isHermesStable || isHermesCanary;
53+
// Hermes V1 (aka Static Hermes) uses more optimised profiles.
54+
// There is currently no difference between stable and canary, but canary
55+
// may in future be used to test features in pre-prod Hermes versions.
56+
const isHermesV1 =
57+
transformProfile === 'hermes-stable' ||
58+
transformProfile === 'hermes-canary';
6059

6160
// We enable regenerator in dev builds for the time being because
62-
// Static Hermes doesn't yet fully support debugging native generators.
61+
// Hermes V1 doesn't yet fully support debugging native generators.
6362
// (e.g. - it's not possible to inspect local variables when paused in a
6463
// generator).
6564
//
6665
// Use native generators in release mode because it has already yielded perf
67-
// wins. The next release of Static Hermes will close this gap, so this won't
66+
// wins. The next release of Hermes will close this gap, so this won't
6867
// be permanent.
69-
const enableRegenerator = isHermes && options.dev;
68+
const enableRegenerator = isHermesV1 && options.dev;
69+
70+
// Preserve class syntax and related if we're using Hermes V1.
71+
const preserveClasses = isHermesV1;
7072

7173
const isNull = src == null;
7274
const hasClass = isNull || src.indexOf('class') !== -1;
73-
const preserveClasses = TRUE_VALS.has(
74-
options?.customTransformOptions?.unstable_preserveClasses,
75-
);
7675

7776
const extraPlugins = [];
7877
const firstPartyPlugins = [];

0 commit comments

Comments
 (0)