Граф коммитов

20 Коммитов

Автор SHA1 Сообщение Дата
Janic Duplessis ae756647c9 Fix babel-plugin-codegen crash when export init is null (#33387)
Summary:
It is possible that `init` is null when using the following code.

```js
export var a;
```

The typescript compiler actually generates something like this for enums so a lot of third party libraries triggered this issue.

For example in expo-apple-authentication/build/AppleAuthentication.types.js

```js
export var AppleAuthenticationScope;
(function (AppleAuthenticationScope) {
    AppleAuthenticationScope[AppleAuthenticationScope["FULL_NAME"] = 0] = "FULL_NAME";
    AppleAuthenticationScope[AppleAuthenticationScope["EMAIL"] = 1] = "EMAIL";
})(AppleAuthenticationScope || (AppleAuthenticationScope = {}));
```

This simply adds a null check.

## Changelog

[General] [Fixed] - Fix babel-plugin-codegen crash when export init is null

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

Test Plan: Tested that this fixed the crash in an app.

Reviewed By: javache

Differential Revision: D34687271

Pulled By: philIip

fbshipit-source-id: 7a7e0fe1bb6a7a21a5b442af26b221a263d4173d
2022-03-11 23:24:22 -08:00
Ramanpreet Nara 971ba5c26b Re-introduce {eventName}: true ViewConfig ValidAttributes in Static ViewConfigs
Summary:
# Problem
I removed the {eventName}: true entries from ViewConfigs validAttributes in D33303950 (ca5aaa7663). These entries were iOS-only. I removed them to achieve platform-consistency in native ViewConfigs.

This change broke the onLayout event for all React Native components. So, I reverted D33303950 (ca5aaa7663) for native ViewConfigs server-side. But I never got around to reverting D33303950 (ca5aaa7663) for static ViewConfigs.

# Changes
This diff reverts D33303950 (ca5aaa7663) for Static ViewConfigs, with server-side gating.

Now, these {eventName}: true ViewConfig validAttribute will be inserted into all view configs (static and native) **by default**.

Calling RCTDisableViewConfigEventValidAttributes(YES) on iOS will remove {eventName}: true ViewConfig ValidAttributes entries from Static ViewConfigs. (Previously, this method only removed the entries from native ViewConfigs).

https://www.internalfb.com/code/fbsource/[6615b0675bdf]/fbobjc/Apps/Wilde/FBReactModule2/FBReactModuleAPI/FBReactModuleAPI/Exported/FBReactModule.mm?lines=344

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D33933403

fbshipit-source-id: 17823ed99f97d7851f04e5cdab9c95667df13253
2022-02-08 19:11:08 -08:00
Paige Sun 63605323b0 2/4 Fix RNHostListComponentListRoute to validate SVCs with NVCs
Summary: Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D33715385

fbshipit-source-id: d8d31e92dd934648f8431a508a78e2813c462f8f
2022-01-25 15:23:46 -08:00
Ramanpreet Nara ca5aaa7663 Remove {eventName}: true from ViewConfig validAttributes
Summary:
For every direct and bubbling event, RCTComponentData (iOS-only) creates a {eventName}: true entry in the component's ViewConfig validAttributes. This entry is unnecessary, and creates a discrepancy between ViewConfigs on iOS vs Android.

This diff removes this entry for all events to:
1. Reduce bloat in native ViewConfigs
2. Create consistency betweeen Android and iOS.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D33303950

fbshipit-source-id: 870c8a2a6d41156ac89bd8554eb09f292bb6108e
2022-01-06 19:09:53 -08:00
Andres Suarez 8bd3edec88 Update copyright headers from Facebook to Meta
Reviewed By: aaronabramov

Differential Revision: D33367752

fbshipit-source-id: 4ce94d184485e5ee0a62cf67ad2d3ba16e285c8f
2021-12-30 15:11:21 -08:00
Sota Ogo 2098c89502 Add babel-plugin-codegen to babel.config.js for fabric (#32756)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/32756

Changelog: [internal] Add babel-plugin-codegen to babel.config.js for the new architecture support.

Reviewed By: motiz88

Differential Revision: D33053216

fbshipit-source-id: 97a1fd9c64972ac4831461b1b62d3a83aa3207cb
2021-12-14 19:28:41 -08:00
Sota Ogo 09b69036c0 Fallback to use lib when src doesn't exist.
Summary:
Changelog: [Internal] babel-plugin-codegen.js to fallback to use lib instead of src.

The bubel plugin uses react-native-codegen/src but it's not compatible when react-native-codegen is installed as a separate dependency (which is the case for OSS).

Reviewed By: cortinico

Differential Revision: D32908846

fbshipit-source-id: 1d3e3a3485e94e2f051e220d76dd2dbcdd8070a8
2021-12-07 12:34:50 -08:00
Tim Yung 77ecc7ede1 JS: Format with Prettier v2.4.1 [3/n]
Summary:
Changelog:
[General][Internal]

Reviewed By: zertosh

Differential Revision: D31883447

fbshipit-source-id: cbbf85e4bf935096d242336f41bf0cc5d6f92359
2021-11-02 22:14:16 -07:00
Moti Zilberman 268efb1022 Use deep require instead of Haste for NativeComponentRegistry
Summary:
Changelog: [Internal]

Some environments that use codegen don't have Haste enabled, breaking the `require('NativeComponentRegistry')` call in generated view configs. Here we change it to reference an explicit path relative to `react-native`.

Reviewed By: JoshuaGross

Differential Revision: D31166063

fbshipit-source-id: cebc23d0d95b5cde76d0f8473eabc03ca82a862e
2021-09-27 13:47:28 -07:00
Moti Zilberman 8db946ade8 Pass configFile: false to Babel parser
Summary:
Changelog: [Internal]

Disables implicit `babel.config.js` lookup in a `parse()` call that does not need any user-specified config.

Reviewed By: javache

Differential Revision: D30396331

fbshipit-source-id: 9b07c361eae53cdffc6a76ba30f1146a7af65a10
2021-08-19 07:03:41 -07:00
Micha Reiser 58a0f9b4e2 Upgrade babel from 7.12.3 -> 7.14.1
Summary:
Changelog:

[General] [Changed] Upgrade Babel from 7.12.3 to 7.14.1

Reviewed By: motiz88

Differential Revision: D27851184

fbshipit-source-id: 59326332d1d188f163cdb034556eea7808824360
2021-05-13 02:48:09 -07:00
Ramanpreet Nara daefa526ad Clean up babel-plugin-codegen snapshot tests
Summary:
Forgot to delete these snapshot tests in D25915169 (e67fc7cada). They are no longer necessary, because we're deleting the JS TurboModule codegen.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D25920310

fbshipit-source-id: 66f6fa3fcba5b53210798a204e4f76e4595b3f25
2021-01-15 11:59:38 -08:00
Ramanpreet Nara e67fc7cada Stop inlining the TurboModule schema in NativeModule specs
Summary:
See title.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D25915169

fbshipit-source-id: 9a5ab08b11fb0d5e9eb47b4a4c579dcff1e60e92
2021-01-14 19:14:23 -08:00
Danny van Velzen fc1ddb6128 Fix typo of TurobModule to TurboModule (#30723)
Summary:
Fix typo in a code comment of babel codegen: TurobModule -> TurboModule
This was discovered in the PR [https://github.com/facebook/react-native/issues/6832](https://github.com/microsoft/react-native-windows/pull/6832) when [microsoft/react-native-windows](https://github.com/microsoft/react-native-windows) ingested latest react-native bits..

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Internal] [Fixed] - Fix a typo in a code comment.

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

Test Plan: None, change is in a comment and most of the scripts like lint-ci don't work on windows.

Reviewed By: shergin

Differential Revision: D25884872

Pulled By: sammy-SC

fbshipit-source-id: 49dfc25d220aa9bc4f7de61c664837b193ae25e5
2021-01-13 08:22:40 -08:00
Evan Gilbert f52e3b3e8b Workaround for react-native-web failing to build
Summary:
There is partially compiled TurboModule code in [NativeAnimatedModule](https://fburl.com/diffusion/g91a70ng) that fails to build with:
`"File neither contains a module declaration, nor a component declaration. For module declarations, please make sure your file has an InterfaceDeclaration extending TurboModule. For component declarations, please make sure your file has a default export calling the codegenNativeComponent<Props>(...) macro"`

This diff removes react-native-web from the TurboModules logic while we work on a cleaner solution, tracked in T80868008

msdkland[metro]
Changelog: [Internal]

Reviewed By: cpojer, RSNara

Differential Revision: D25325163

fbshipit-source-id: 346abf52660073f976b0f978cbfbfc8402f4b3ee
2020-12-08 17:45:28 -08:00
Ramanpreet Nara e289366b38 Move TurboModuleRegistry validation into NativeModule Spec Parser
Summary:
## Changes
1. In the NativeModule spec parser, the moduleName is now being extracted from the TurboModuleRegistry.get<Spec>(...) call by examining the Flow ast node. Previously, we used regex parsing, which was unsafe because it could be fooled by TurboModuleRegistry.get<Spec>(...) calls in comments.
2. The logic to parse and validate the TurboModuleRegistry.get<Spec>(...) call is now centralized in the NativeModule Spec Parser (it was removed from the react-native-modules ESLint rule). The linter is now only responsible for three things:
   1. Detecting if a JavaScript file contains a TurboModuleRegistry.get<Spec> call or a TurboModule interface, and if so
   2. Running the NativeModule spec parser on it.
   3. It also validates that the Module spec's filename starts with the prefix "Native".

The React Native Modules linter now completely delegates to the NativeModules Spec parser, without doing any error checking of its own. If an error is reported by the React Native Modules linter, and that error doesn't have anything to do with the "Native" prefix, then it *must* be addressed. Otherwise, it will cause the NativeModule Spec Parser to fail on that particular spec.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D25153243

fbshipit-source-id: da74dbb66b1d8dca3a2b1952402222c6696b73d6
2020-12-04 14:21:52 -08:00
Tim Yung baa824826d RN: Call `NativeComponentRegistry` in Codegen
Summary:
Changes `react-native/babel-plugin-codegen` to generate calls to `NativeComponentRegistry` instead of `registerGeneratedViewConfig`.

The only notable changes in behavior from this will be:

1. In bridgeless mode, all components using `codegenNativeComponent` will no longer access `UIManager`.
2. In bridge mode, all components using `codegenNativeComponent` will no longer verify equivalence in production. Only in `__DEV__`. (This may improve performance slightly.)

This also changes the `ViewConfig` to be lazily allocated and drops support for `__INTERNAL_VIEW_CONFIG`, which we no longer need.

Changelog:
[Internal]

Reviewed By: JoshuaGross

Differential Revision: D25135881

fbshipit-source-id: ca2191872c02622ab2279b808102eeb1f664d207
2020-11-22 01:32:08 -08:00
Ramanpreet Nara b6a72bac69 Extend babel-plugin-codegen to generate TurboModule JS codegen
Summary:
## New Functionality
- Detect if the JS file represents a NativeModule spec.
  - **Note:** A JS file is a NativeModule spec if it contains a flow `interface` that extends `TurboModule`. This logic is copied over from the OSS Codegen, here: 7ccb67a49c/packages/react-native-codegen/src/parsers/flow/index.js (L60-L75)
- For all NativeModule specs, generate the spec's schema using the OSS Codegen for Modules, and conditionally inline it into every `TurboModuleRegistry.get(Enforcing)?` call in the spec, like so:

**Before:**
```
/**
 * flow
 */

import type {TurboModule} from 'RCTExport';
export interface Spec extends TurboModule {
  //...
}

export default TurboModuleRegistry.get<Spec>('FooModule');
```

**After:**
```
/**
 * flow
 */

import type {TurboModule} from 'RCTExport';
export interface Spec extends TurboModule {
  //...
}

export default TurboModuleRegistry.get<Spec>('FooModule', __getModuleShape());

function __getModuleShape() {
  if (!(global.RN$EnableTurboModuleJSCodegen === true)) {
    return undefined;
  }

  return {...};
}
```

Changelog: [General][Added] Extend react-native/babel-plugin-codegen to generate TurboModule JS codegen

Reviewed By: TheSavior

Differential Revision: D22803845

fbshipit-source-id: 18c157a1dbfcc575012184de31c38908acd53c36
2020-11-08 14:24:05 -08:00
simek 29f5dc2ae0 chore: deduplicate lock, update packages repository fields (#30044)
Summary:
This small PR includes the following changes:
* deduplicate yarn lock file using [`yarn-deduplicate`](https://github.com/atlassian/yarn-deduplicate) package
  * deduplicate script has been added as `update-lock`, let me know if you would like also to see this in [`postinstall`](https://docs.npmjs.com/misc/scripts) (to automatically optimize lock on every dependency change)
* according to the [npm docs](https://docs.npmjs.com/files/package.json#repository):
  * main `package.json` repository field has been replaced with shorthand
  * monorepo packages repository field has been extended by `directory`

The main goal of introducing deduplication script was to optimize the dependencies footprint while developing and speed up the initial installation process. Running `yarn-deduplicate` also increase the security in some way, because it enforces usage only of the latest version of the package. You can read more about the benefits in the deduplicate script [repository](https://github.com/atlassian/yarn-deduplicate#duplicated-packages).

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Internal] [Added] - add yarn lock deduplication script

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

Test Plan: `yarn install` was successful, this also should not affect yarn workspaces in any way.

Reviewed By: GijsWeterings

Differential Revision: D23959812

Pulled By: cpojer

fbshipit-source-id: e2455e3718378e1ce6206e79463d4083f8fe5d47
2020-09-28 22:41:50 -07:00
Ramanpreet Nara 4cbc39a431 Rename babel-plugin-inline-view-configs to @react-native/babel-plugin-codegen
Summary:
This babel plugin will also take care of the JS TurboModule Codegen. Therefore, we should rename this into something more generic.

Changelog:
[General][Changed] Rename babel-plugin-inline-view-configs to react-native/babel-plugin-codegen

Reviewed By: rickhanlonii, cpojer

Differential Revision: D22803209

fbshipit-source-id: 416c97fea6fa0820d25bbc91033a0cbbbbbff825
2020-07-31 13:00:50 -07:00