Skip to content

Commit 2e1d711

Browse files
yungstersreact-native-bot
authored andcommitted
RN: Default Hermes Parser to reactRuntimeTarget: "19" (#52625)
Summary: Pull Request resolved: #52625 Changes `react-native/babel-preset` so that by default, `hermes-parser` is configured with `reactRuntimeTarget: "19"`. This changes the compiled output of Component Syntax to not use `forwardRef` when a `ref` prop is present. Additionally, this adds a new preset option property, `hermesParserOptions`. This object allows users of `react-native/babel-preset` to supply overrides for any `hermes-parser` options. Changelog: [General][Changed] - Configures `react-native/babel-preset` to target React 19 by default, meaning Component Syntax will not compile to `forwardRef` calls when a `ref` prop is present. [General][Added] - Added support to `react-native/babel-preset` for a `hermesParserOptions` option, that expects an object that enables overriding `hermes-parser` options. Reviewed By: SamChou19815 Differential Revision: D78383269 fbshipit-source-id: 1e6b66b9bfbeaf8a06fdc39031cb6de7e921765f
1 parent 14bfad5 commit 2e1d711

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

  • packages/react-native-babel-preset/src/configs

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

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,6 @@ function isFirstParty(fileName) {
3838
// use `this.foo = bar` instead of `this.defineProperty('foo', ...)`
3939
const loose = true;
4040

41-
const defaultPlugins = [
42-
[require('babel-plugin-syntax-hermes-parser'), {parseLangTypes: 'flow'}],
43-
[require('babel-plugin-transform-flow-enums')],
44-
[require('@babel/plugin-transform-block-scoping')],
45-
[require('@babel/plugin-transform-class-properties'), {loose}],
46-
[require('@babel/plugin-transform-private-methods'), {loose}],
47-
[require('@babel/plugin-transform-private-property-in-object'), {loose}],
48-
[require('@babel/plugin-syntax-dynamic-import')],
49-
[require('@babel/plugin-syntax-export-default-from')],
50-
...passthroughSyntaxPlugins,
51-
[require('@babel/plugin-transform-unicode-regex')],
52-
];
53-
5441
// For Static Hermes testing (experimental), the hermes-canary transformProfile
5542
// is used to enable regenerator (and some related lowering passes) because SH
5643
// requires more Babel lowering than Hermes temporarily.
@@ -234,7 +221,28 @@ const getPreset = (src, options) => {
234221
plugins: [require('@babel/plugin-transform-flow-strip-types')],
235222
},
236223
{
237-
plugins: defaultPlugins,
224+
plugins: [
225+
[
226+
require('babel-plugin-syntax-hermes-parser'),
227+
{
228+
parseLangTypes: 'flow',
229+
reactRuntimeTarget: '19',
230+
...options.hermesParserOptions,
231+
},
232+
],
233+
[require('babel-plugin-transform-flow-enums')],
234+
[require('@babel/plugin-transform-block-scoping')],
235+
[require('@babel/plugin-transform-class-properties'), {loose}],
236+
[require('@babel/plugin-transform-private-methods'), {loose}],
237+
[
238+
require('@babel/plugin-transform-private-property-in-object'),
239+
{loose},
240+
],
241+
[require('@babel/plugin-syntax-dynamic-import')],
242+
[require('@babel/plugin-syntax-export-default-from')],
243+
...passthroughSyntaxPlugins,
244+
[require('@babel/plugin-transform-unicode-regex')],
245+
],
238246
},
239247
{
240248
test: isTypeScriptSource,

0 commit comments

Comments
 (0)