Commit Graph

23 Commits

Author SHA1 Message Date
Danny Su fb0e4ee6d1 Enable regenerator for Hermes dev mode transform profile (#52651)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/52651

Changelog: [Internal]

Last year the `hermes-canary` profile was used to enable certain apps to use Static Hermes by enabling regenerator because debugger support for generator wasn't finished yet. However, we actually could have just keyed off of `options.dev` and still kept using `hermes-stable`.

The `hermes-canary` profile is actually meant to be used to run experiments. We should free up this profile to return it to the original intended purpose.

This diff makes all hermes profiles' dev mode use regenerator. Existing SH apps using `hermes-canary` should be unaffected. And apps using Hermes will change to use regenerator in dev mode, but that should be ok.

Reviewed By: robhogan

Differential Revision: D78450695

fbshipit-source-id: eb6a87fbc1f0e08d490fd0d1baa3611248f95764
2025-07-28 21:44:45 -07:00
Tim Yung 0508eddfe6 RN: Default Hermes Parser to reactRuntimeTarget: "19" (#52625)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/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
2025-07-17 12:53:36 -07:00
Tim Yung 742ffa39fb RN: Update Fantom Path in EXCLUDED_FIRST_PARTY_PATHS (#52051)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/52051

In {D76368959}, I moved `react-native-fantom` from `packages/` to `private/` and missed this reference.

Changelog:
[Internal]

Reviewed By: rubennorte

Differential Revision: D76743071

fbshipit-source-id: f99d3f2ac5e14fd23f7cf208ca030541844dddc6
2025-06-17 02:59:42 -07:00
Tim Yung b344aec2ae RN: Add @noflow to ESLint & Babel Preset Files (#51778)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51778

Adds `noflow` to a bunch of ESLint and Babel files that are expected to be evaluated using Node.js without Babel. Additioanlly, these files tend to depend on ESLint and Babel type definitions that are not currently readily available.

In the future, these files could be migrated to use `flow strict-local` or `flow strict` using comment syntax for type annotations. But for now, adding `noflow` makes it explicit that these are known to not be typechecked.

Changelog:
[Internal]

Reviewed By: SamChou19815

Differential Revision: D75883642

fbshipit-source-id: 54236d123ca8773de42bce81189dfb5c0671563e
2025-06-04 12:03:52 -07:00
Tim Yung 1977dd6596 RN: Sort Pragmas in Headers (#51554)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51554

Sorts pragma directives file headers in React Native.

Changelog:
[Internal]

Reviewed By: SamChou19815

Differential Revision: D75264593

fbshipit-source-id: 9e4b253dd0fc94dc2fc469d7114b93a8aae305f4
2025-05-22 21:18:53 -07:00
Tim Yung 84de8a075e RN: Delete @oncall Annotations (#51416)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51416

Deletes `oncall` annotations from the `facebook/react-native` repository.

Changelog:
[Internal]

Reviewed By: javache

Differential Revision: D74902524

fbshipit-source-id: 32a6a5b2ff27281792d572f151e2b094d9a79029
2025-05-17 16:18:05 -07:00
Tim Yung ba092bfaba RN: Add Missing @format Annotations (#51415)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51415

Adds the `format` annotation to all files that were missing them.

Also, adds `noformat` to generated files, and removed it from files that no longer need them.

Changelog:
[Internal]

Reviewed By: SamChou19815

Differential Revision: D74901034

fbshipit-source-id: 7e0b85ca8ee2de41278f3aa23cb03e9c266d9c28
2025-05-16 18:09:09 -07:00
Dawid Małecki a120c5c4db Ignore warnings for imports from react-native/Libraries/Core/InitializeCore (#50903)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/50903

For now we do not change the way this module is exported to prevent breaking changes (due to high usage in external packages).  It is a tentative mitigation - this case requires more discussion and what could be sufficient. The `no-deep-imports` rule and plugin shouldn't emit a warning when encountered.

Changelog:
[Internal]

Reviewed By: huntie

Differential Revision: D73590627

fbshipit-source-id: 6f85c52373ee6c7c538c632b55cd9e0b9357f2a3
2025-04-28 05:32:11 -07:00
Dawid Małecki 3e14d1638c Add babel plugin to @react-native/babel-preset for console.warn injection under deep react native imports (#50802)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/50802

The plugin analyses the source of all `import`, `require`, and `export` statements and injects the `console.warn` statement for each path targeting deep react-native source code. It runs only on a dev mode so there is no need to keep that in the `if (__DEV__) ` block. It is possible to disable this plugin by setting `disableDeepImportWarnings: true` and **resetting** the Metro cache:

```js
module.exports = {
  presets: [['module:react-native/babel-preset', {
    "disableDeepImportWarnings": true
  }]],
};
```

Changelog:
[General][Internal] - Added plugin to react-native/babel-preset injecting `console.warn` for each react native deep import in dev mode.

For a given code:
```js
import { Image } from 'react-native';
import View from 'react-native/Libraries/Components/View/View';
const Text = require('react-native/Libraries/Text/Text');
export { PressabilityDebugView } from 'react-native/Libraries/Pressability/PressabilityDebug';
```

The transformed output should look like:

```js
import { Image } from 'react-native';
import View from 'react-native/Libraries/Components/View/View';
const Text = require('react-native/Libraries/Text/Text');
export { PressabilityDebugView } from 'react-native/Libraries/Pressability/PressabilityDebug';
console.warn("Deep imports from the 'react-native' package are deprecated ('react-native/Libraries/Components/View/View').");
console.warn("Deep imports from the 'react-native' package are deprecated ('react-native/Libraries/Text/Text').");
console.warn("Deep imports from the 'react-native' package are deprecated ('react-native/Libraries/Pressability/PressabilityDebug').");
```

For more information about why this plugin was needed, please check [RFC](https://github.com/react-native-community/discussions-and-proposals/pull/894).

Reviewed By: huntie

Differential Revision: D70783145

fbshipit-source-id: ae145db6471d861099566a8faf2fbd93bd136450
2025-04-24 08:04:21 -07:00
Joseph Nields 86911003dc Add compact option (#49979)
Summary:
If you use this preset to create library code, it is often helpful to be able to still read the transpiled code, even when sourcemaps are available.

This change adds a compact option which allows for disabling the default behavior that removes whitespace from the transpiled files.

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[GENERAL] [ADDED] - Add `compact` option to `react-native/babel-preset` to allow disabling whitespace removal

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests

Pull Request resolved: https://github.com/facebook/react-native/pull/49979

Reviewed By: rshest

Differential Revision: D71109024

Pulled By: robhogan

fbshipit-source-id: ab205cca2a82b56955d1e1c55e288dcbe7754f8f
2025-03-13 09:22:23 -07:00
Alex Hunt 3de9892353 Skip hermes-parser under Babel for non-Flow JS code (#47568)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/47568

Resolves https://github.com/facebook/hermes/issues/1549.

Changelog:
[General][Fixed] - When using Babel with plain JavaScript files, support for additional user syntax plugins should be fixed (now uses Babel's parser instead of hermes-parser). There is no change for JS files annotated with `flow`, where extended JS syntax remains unsupported.

Reviewed By: blakef

Differential Revision: D65816797

fbshipit-source-id: 9f05e86019548ac8727ee65c2e2c417d78a406d8
2024-11-21 05:41:39 -08:00
Alex Hunt 1387f521fd Switch Babel parsing from legacy Flow plugin to hermes-parser (#46696)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/46696

Following D62161923, we began to lose sync with modern Flow syntax when Metro's `transformer.hermesParser` option is disabled. This config option loads Babel for transformation (instead of `hermes-parser`), which requires a Babel plugin to parse (not strip) Flow syntax.

This diff migrates us away from `babel/plugin-syntax-flow` (see also https://github.com/babel/babel/issues/16264) and uses the modern [`babel-plugin-syntax-hermes-parser`](https://www.npmjs.com/package/babel-plugin-syntax-hermes-parser) instead (a component of the modern Hermes Parser stack).

Following this change, new projects that unset `transformer.hermesParser` will compile.

Resolves https://github.com/facebook/react-native/issues/46601.

Changelog:
[General][Fixed] - Fix parsing of modern Flow syntax when `transformer.hermesParser = false` is configured in Metro config

Reviewed By: cipolleschi

Differential Revision: D63535216

fbshipit-source-id: d2c6ddec030d89e2698e03b76194cf3568d04e6b
2024-09-27 10:20:19 -07:00
Aakash Patel a0237e96f1 Enable regenerator transform for hermes-canary (#44668)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44668

Enables regenerator for `hermes-canary`. Along with the previous diff, regenerator is the only difference between `hermes-stable` and `hermes-canary`.

Reviewed By: motiz88

Differential Revision: D57742907

fbshipit-source-id: ca14cb50fe976744c7fa2c0b3397e81661359f15
2024-05-31 12:03:04 -07:00
Aakash Patel b5b497ff10 Align hermes-canary and hermes-stable profiles (#44728)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44728

This makes them identical so the diff that makes them diverge is clear.

Changelog: [Internal]

Reviewed By: motiz88

Differential Revision: D57970711

fbshipit-source-id: 8586ef202ad27796918378832fa62df1708a0218
2024-05-31 12:03:04 -07:00
Tim Yung cdc3b9cdfc RN: Disable Babel Plugin for Arrow Functions for Hermes (#44534)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44534

Reapplies {D50818568} (reverted by D50885400).

Changelog:
[General][Changed] - Disable Babel plugin for arrow functions for Hermes

Reviewed By: robhogan

Differential Revision: D57242622

fbshipit-source-id: 63ec2aeb7562dbb1a049dedd6a35b10aa822193c
2024-05-13 08:45:14 -07:00
kaganece 6213b2a62a fix: deprecated babel plugins issue fixed (#44416)
Summary:
In this pr, I updated the deprecated babel-plugins with their new library. When you enter the npm page of the relevant plugins, it is recommended to implement new packages instead of the deprecated package.
For example :

<img width="1305" alt="Screenshot 2024-05-05 at 17 50 16" src="https://github.com/facebook/react-native/assets/113903710/a58fdac3-79db-4b53-98bd-4c5325a1e560">

## Motivation:

We use the react-native package in our project and aim to upgrade pnpm to the latest version. First, we wanted to clear deprecated warnings. Babel plugin deprecated warnings were caused by the react-native package, so I created this pull request.
Deprecation Warnings from package installing :

<img width="581" alt="Screenshot 2024-05-05 at 17 53 05" src="https://github.com/facebook/react-native/assets/113903710/9c5859a5-f194-43ab-ae35-417dfaacebab">

## Changelog:

[GENERAL][FIXED] - Replace deprecated babel-plugin libraries to fix deprecation warnings on installation

Pull Request resolved: https://github.com/facebook/react-native/pull/44416

Test Plan: CI should pass

Reviewed By: huntie

Differential Revision: D57056843

Pulled By: robhogan

fbshipit-source-id: b75b329bbc2105c31da85e861ef71ffdcbbb0623
2024-05-08 12:51:00 -07:00
Jon Thysell (JAUNTY) c90485eb10 Add detection of logical assignment operators to react-native-babel-preset (#39186)
Summary:
Though not currently in use in the RN code, when `react-native-windows` tried to integrate changes up to 7/28/23 (see PR https://github.com/microsoft/react-native-windows/pull/11970) there happened to be a `??=` operator in the `virtualized-lists` package (see [diff here](https://github.com/facebook/react-native/compare/ccc50ddd2...c168a4f88#diff-abeff2daf5909e54a23562e43569de1d5b8db1d7170119eed485b618cdf04ec7R322)). (The offending line was removed in a later commit).

The default RNW engine is still Chakra and it couldn't handle the syntax. It looks like the `babel/plugin-proposal-nullish-coalescing-operator` plugin only handles `??`, so to handle `??=` I've added `babel/plugin-proposal-logical-assignment-operators`, which also happens to handle the logical assignment operators `||=` and `&&=`.

Closes https://github.com/facebook/react-native/issues/31704

## Changelog:

[GENERAL] [FIXED] - Add detection of logical assignment operators to `react-native-babel-preset`

Pull Request resolved: https://github.com/facebook/react-native/pull/39186

Test Plan: We started using these plugins in RNW's babel config to resolve the issue in our integrate PR.

Reviewed By: motiz88

Differential Revision: D50936554

Pulled By: rozele

fbshipit-source-id: 0a924b6085524d8c9551a158b91195b1f7448c19
2023-11-06 08:52:25 -08:00
Gijs Weterings f3a916f3ae Back out "Apply Babel arrow transform only when needed" (#41282)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41282

Original commit changeset: ad96540bb777

Original Phabricator Diff: D50818568

Changelog: [Internal]

Reviewed By: robhogan

Differential Revision: D50885400

fbshipit-source-id: b5039b6430e48a3b87456758bf4fef6cc182ee8f
2023-11-01 09:22:33 -07:00
dan 9a3b75c782 Apply Babel arrow transform only when needed (#41253)
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 https://github.com/facebook/metro/commit/beb3d1ab5dc46a856e0810f3c0787f8885c8f654 (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 https://github.com/facebook/react/pull/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: https://github.com/facebook/react-native/pull/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
2023-10-31 05:55:26 -07:00
Dmitry Rykun 59e6b11fbc Add @react-native/babel-plugin-codegen to the preset if src is null (#39159)
Summary:
X-link: https://github.com/facebook/metro/pull/1078

Pull Request resolved: https://github.com/facebook/react-native/pull/39159

Source is not required for `getPreset` of `react-native/babel-preset`. There is a codition that adds `react-native/babel-plugin-codegen` to the preset only if source is passing certain regex. This condition fails if source is null, but that's wrong because the plugin may still be requred for this transformation even though source is not provided.
This diff changes the condition so the regexp tests source only if it is not null, and `react-native/babel-plugin-codegen` automatically added to the preset otherwise.
Changelog: [Internal]

Reviewed By: robhogan

Differential Revision: D48684443

fbshipit-source-id: 7cea69c91c0175ac0374d72e91f58e20fe75fd53
2023-09-14 08:25:40 -07:00
Tim Yung db4a253c1e RN: Support Private Methods & Properties (#39318)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39318

Updates `react-native/babel-preset` to support private methods and properties.

Changelog:
[General][Added] Added plugins for private methods and properties to `react-native/babel-preset`.

Reviewed By: asiandrummer

Differential Revision: D49029339

fbshipit-source-id: 2e0578886b22770d3f037ce184b842ee15a59c8e
2023-09-11 13:39:50 -07:00
Dmitry Rykun 1c3b3a09b6 Add @react-native/babel-plugin-codegen to @react-native/babel-preset (#38227)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/38227

X-link: https://github.com/facebook/metro/pull/1023

This diff enables react-native/babel-plugin-codegen to react-native/babel-preset. This will enable static view configs generation for properly schematized native components.

Changelog: [General][Changed] - react-native/babel-plugin-codegen to react-native/babel-preset

Reviewed By: christophpurrer

Differential Revision: D46688516

fbshipit-source-id: ebecc5fd610ca4b86c55355879ad3fd36d51cae9
2023-08-01 07:49:23 -07:00
Dmitry Rykun d380bb8473 Move react-native-babel-transformer and react-native-babel-preset from Metro to React Native repo (#38228)
Summary:
X-link: https://github.com/facebook/metro/pull/1024

Pull Request resolved: https://github.com/facebook/react-native/pull/38228

Changelog: [General][Changed] - Move react-native-babel-transformer and react-native-babel-preset from Metro to React Native repo.

Metro Changelog:  **[Breaking]** - Remove `metro-react-native-babel-transformer` and `metro-react-native-babel-preset`, to be published as `react-native/metro-babel-transformer` and `react-native/babel-preset` instead.

This diff does the following:
- Move `metro/packages/metro-react-native-babel-preset` to `react-native/packages/react-native-babel-preset`.
- Rename `metro-react-native-babel-preset` package to `react-native/babel-preset`.
- Move `metro/packages/metro-react-native-babel-transformer` to `react-native/packages/react-native-babel-transformer`.
- Rename `metro-react-native-babel-transformer` package to `react-native/metro-babel-transformer`.
- Upadate dependencies.

Reviewed By: robhogan

Differential Revision: D46977466

fbshipit-source-id: 32478f63a0442b61a1804f12ef814c8b29d7f8bb
2023-07-27 11:48:16 -07:00