Commit Graph

506 Commits

Author SHA1 Message Date
Sam Zhou 82e86c459d Annotate empty arrays in xplat (2/n)
Summary: Changelog: [Internal]

Reviewed By: pieterv

Differential Revision: D40460690

fbshipit-source-id: 1e10b0bcf874dc9a3702b4d17d30d448653602ca
2022-10-18 12:49:22 -07:00
Riccardo Cipolleschi 62da9b8ce2 Backout Generate Custom Native State from Codegen
Summary:
This is the second diffs that backs out the Custom Native State from the Codegen. The reason why we are backing it out are:

1. It forces users to create new types in JS that are not ctually used there. For example, the NativeState you define, and eventually exports, in JS is not used anywhere in your JS code.
2. You need to put in the JS native state some types that does not exists in JS, only to have them generated by the Codegen. ImageRequest, for example, does not exists in JS, but you need it in your (iOS) state to load images
3. There are a lot of edge cases due to how C++ handles variables. Some variables needs to be created as pointers. Some others as `const &`. It does not scale to hard code all of them and there is the risk to have the same type that needs to be a pointer in some case and something else in others.
4. It is better to instruct the users on how to properly create a component with Custom State, Shadow Node and Descriptor.

## Changelog:
[General][Removed] - Back out parsing and generation of Custom Native State from Codegen

Reviewed By: cortinico

Differential Revision: D40426134

fbshipit-source-id: c368e122cc31ee8df056fe1bf6cecaab482140a4
2022-10-18 10:30:06 -07:00
youedd 633498fe9a refactor module's platform verification (#34961)
Summary:
Part of https://github.com/facebook/react-native/issues/34872

> [Assigned to youedd] Extract the nameToValidate logic ([Flow](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/flow/modules/index.js#L704-L713), [TypeScript](https://github.com/facebook/react-native/blob/f353119113d6fc85491765ba1e90ac83cb00fd61/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L738-L747)) into a shared function into the parser/utils.js file. Notice that you may need a callback to update the cxx boolean.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Changed] [Internal] - refactor parser module platform verification

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

Test Plan:
`yarn jest react-native-codegen`

![image](https://user-images.githubusercontent.com/19575877/195425654-46f9e560-efd3-4945-b913-c6d9f6bb7ec2.png)

Reviewed By: cipolleschi

Differential Revision: D40319245

Pulled By: skinsshark

fbshipit-source-id: bc36cdcfa06047e1acee0d638f5756b6462d76d1
2022-10-17 11:08:06 -07:00
Mohit Charkha 9fb3700d35 Extract MisnamedModuleInterfaceParserError from Flow and Typescript into error-utils.js (#34916)
Summary:
This PR is part of https://github.com/facebook/react-native/issues/34872
This PR extracts MisnamedModuleFlowInterfaceParserError exception to a separate function inside an error-utils.js file

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal] [Changed] - Extract MisnamedModuleInterfaceParserError to a seperate function inside error-utils.js

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

Test Plan:
yarn jest react-native-codegen
Added unit case in `error-utils-test.js` file

<img width="980" alt="Extract MisnamedModuleInterfaceParserError test Screenshot" src="https://user-images.githubusercontent.com/86604753/194853899-22c1ce05-fe55-4102-a83b-15c707a20000.png">

Reviewed By: cipolleschi

Differential Revision: D40226541

Pulled By: motiz88

fbshipit-source-id: 6698ceff192c592383aa3419ac31de524c605919
2022-10-17 06:47:13 -07:00
Antoine Doubovetzky 3c8d678aad Extract visit function to parsers/utils (#34946)
Summary:
This PR is a task from https://github.com/facebook/react-native/issues/34872:
> Extract the visit function in a shared function in the parsers/utils.js folder. Use the new function in the Flow and TypeScript parsers.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal] [Changed] - Extract the visit function in a shared function in the parsers/utils.js

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

Test Plan: I tested using jest, flow and eslint commands.

Reviewed By: NickGerleman

Differential Revision: D40276462

Pulled By: cipolleschi

fbshipit-source-id: 299cc2a3aa65a9757b217192a13838d037c497a1
2022-10-17 02:35:27 -07:00
mohitcharkha f645404f5c Extracted UnsupportedModulePropertyParserError into throwIfModuleTypeIsUnsupported function in error-utils.js file (#34966)
Summary:
This PR is part of https://github.com/facebook/react-native/issues/34872
This PR extracts `UnsupportedModulePropertyParserError` exception to `throwIfModuleTypeIsUnsupported` function inside `error-utils.js` file

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal] [Changed] - Extract `UnsupportedModulePropertyParserError` to `throwIfModuleTypeIsUnsupported` function inside `error-utils.js`

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

Test Plan:
`yarn jest react-native-codegen`
Added unit case in `error-utils-test.js` file

<img width="939" alt="Screenshot 2022-10-13 at 12 14 19 PM" src="https://user-images.githubusercontent.com/86604753/195521643-6a197b51-7038-48f1-8b92-2c8c2786d66b.png">

Reviewed By: christophpurrer

Differential Revision: D40337936

Pulled By: cipolleschi

fbshipit-source-id: 74fb116b48634c5e3b6c11f8b71ad59f290d959e
2022-10-14 03:09:51 -07:00
dhruvtailor7 1e15e21348 extracted UntypedModuleRegistryCallParserError to a throwing function in error-utils.js (#34953)
Summary:
This PR is part of https://github.com/facebook/react-native/issues/34872.
As a part of this PR, `UntypedModuleRegistryCallParserError` is separated into its own throwing function in `error-utils.js` file and is used in both Flow and TypeScript parsers

## Changelog

[Internal] [Changed] - Extract `UntypedModuleRegistryCallParserError` to a separate function inside `error-utils.js` file.

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

Test Plan:
Added unit case in error-utils-test.js file to test the new function.
Output of `yarn jest react-native-codegen` ensures all passed test cases.

<img width="450" alt="Screenshot 2022-10-12 at 12 44 36 PM" src="https://user-images.githubusercontent.com/32268377/195277708-97340db3-f3d8-48a3-9a59-95d2747c67b0.png">

Reviewed By: christophpurrer

Differential Revision: D40297017

Pulled By: cipolleschi

fbshipit-source-id: b02dcf0e110ab903a0d1831783194ae4a543075b
2022-10-14 03:09:51 -07:00
Tarun Chauhan b87d371a38 extract emitMixedTypeAnnotation to parsers-commons (#34954)
Summary:
Create a function emitMixedTypeAnnotation into the parsers-commons.js file to put together this code from [Flow](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/flow/modules/index.js#L400-L404) and [TypeScript](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L435-L440).

Part of https://github.com/facebook/react-native/issues/34872

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal] [Changed] - Extract emitMixedTypeAnnotation into the parsers-commons

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

Test Plan:
run ```yarn jest react-native-codegen```

<img width="781" alt="image" src="https://user-images.githubusercontent.com/34857453/195291603-f138c64c-1b49-41af-a133-ee366d02706a.png">

Reviewed By: NickGerleman

Differential Revision: D40297103

Pulled By: cipolleschi

fbshipit-source-id: 3ee3569fbfa850ac50df18b74ecc3eefbeb267c9
2022-10-14 03:09:51 -07:00
mohitcharkha c403cd4f11 Extracted content of the case FunctionTypeAnnotation into emitFunction in parsers-primitives file (#34950)
Summary:
This PR is part of https://github.com/facebook/react-native/issues/34872
This PR extracts the content of the case `FunctionTypeAnnotation` into a single `emitFunction` function inside the parsers-primitives.js file and uses it in both Flow and TypeScript parsers

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal] [Changed] - Extract the content of the case `FunctionTypeAnnotation` into a single `emitFunction` function

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

Test Plan:
Run yarn jest react-native-codegen and ensure CI is green
<img width="984" alt="Screenshot 2022-10-12 at 11 18 54 AM" src="https://user-images.githubusercontent.com/86604753/195260414-136f918f-e4b7-4fcf-b0b9-9142872f3cf9.png">

Reviewed By: christophpurrer

Differential Revision: D40296823

Pulled By: cipolleschi

fbshipit-source-id: 3cac407d260481bd6ae7c3e46642e4c16bba3376
2022-10-14 03:09:51 -07:00
dakshbhardwaj 1eaa092daf extracted nullguard function to parsers-util.js file (#34952)
Summary:
This PR is a part of https://github.com/facebook/react-native/issues/34872
This PR extracts Extract the `nullGuard` function ([Flow](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L74-L76), [TypeScript](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L74-L76)) into a function in the `parsers-utils.js` file

## Changelog
[Internal] [Changed] - Extracted `nullGuard` function from flow and typescript to a file `parsers-utils.js`.

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

Test Plan:
yarn jest react-native-codegen
<img width="1042" alt="Screenshot 2022-10-12 at 12 52 02 PM" src="https://user-images.githubusercontent.com/22423684/195277414-dc0122f4-603a-4e93-aef1-2ac0c33a960d.png">

Reviewed By: NickGerleman

Differential Revision: D40296951

Pulled By: cipolleschi

fbshipit-source-id: 4fb305fff2e28025496b65ec697d2a59cff77bde
2022-10-14 03:09:51 -07:00
MaeIg c388e6c689 Wrap the content of the case Array and case $ReadOnlyArray in Flow into a separate function (#34948)
Summary:
This PR aims to extract translateArrayTypeAnnotation logic into a separate function as it is done in typescript folder. This will enable us to extract translateArrayTypeAnnotation function into a shared folder in a later step. It is a task of https://github.com/facebook/react-native/issues/34872:
> Wrap the content of the case Array: and case ReadOnlyArray in [Flow](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/flow/modules/index.js#L106-L107) into a separate function, as it is for the [TypeScript](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L218-L234) parser. This will enable us to unify the two parsers in a later step.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[Internal] [Changed] - Wrap the content of the case Array and case $ReadOnlyArray in Flow into a separate function

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

Test Plan:
yarn flow:
<img width="645" alt="image" src="https://user-images.githubusercontent.com/40902940/195200715-7f60d927-e262-4a94-ad91-a884d37726b8.png">

yarn lint:
<img width="502" alt="image" src="https://user-images.githubusercontent.com/40902940/195200799-7959e068-b5b7-4242-a7b1-7afd80866d7f.png">

yarn jest react-native-codegen:
<img width="381" alt="image" src="https://user-images.githubusercontent.com/40902940/195200775-76957c19-d06d-431c-8555-889a4205374e.png">

Reviewed By: dmytrorykun

Differential Revision: D40296730

Pulled By: cipolleschi

fbshipit-source-id: ad2d965046e25ee000ae6e07075976e5a0c78f1a
2022-10-14 03:09:51 -07:00
harshsiriah bb519ecccb Extracted IncorrectModuleRegistryCallTypeParameterParserError to throwIfIncorrectModuleRegistryCallTypeParameterParserError (#34941)
Summary:
This PR is part of https://github.com/facebook/react-native/issues/34872.
This PR extracts `IncorrectModuleRegistryCallTypeParameterParserError` exception to a separate function inside an `error-utils.js` file

## Changelog

[Internal] [Changed] - Extract `IncorrectModuleRegistryCallTypeParameterParserError` to a seperate function inside `error-utils.js`

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

Test Plan:
```sh
yarn jest react-native-codegen
```
Added unit case in `error-utils-test.js` file

<img width="940" alt="Screenshot 2022-10-11 at 4 42 03 PM" src="https://user-images.githubusercontent.com/86605635/195076564-3b023c17-661c-4330-805c-0216c4391d59.png">

Reviewed By: dmytrorykun

Differential Revision: D40296642

Pulled By: cipolleschi

fbshipit-source-id: 7c7bba6a4f68e9b8fa4729a7651f22cce6d7ca6e
2022-10-14 03:09:51 -07:00
dakshbhardwaj 76c5b6f7bf Extracted IncorrectModuleRegistryCallArityParserError as a seperate function in error-utils.js (#34940)
Summary:
This PR is part of https://github.com/facebook/react-native/issues/34872
This PR extracts `IncorrectModuleRegistryCallArityParserError` exception to `throwIfIncorrectModuleRegistryCallArityParserError` inside an `error-utils.js` file.

## Changelog
[Internal] [Changed] - Extracted IncorrectModuleRegistryCallArityParserError exception to throwIfIncorrectModuleRegistryCallArityParserError function

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

Test Plan:
Added unit case in error-utils-test.js file

 yarn jest react-native-codegen

<img width="1144" alt="Screenshot 2022-10-11 at 4 04 55 PM" src="https://user-images.githubusercontent.com/22423684/195070498-627d1bb8-53b1-43d3-b410-462e4f0da23a.png">

Reviewed By: dmytrorykun

Differential Revision: D40296626

Pulled By: cipolleschi

fbshipit-source-id: 33a299b1adf6334753c2390a81a54832c9096ec5
2022-10-14 03:09:51 -07:00
Vinay Harwani a33f672625 Extracted UnusedModuleInterfaceParserError to throwIfUnusedModuleInterfaceParserError in error-utils.js (#34939)
Summary:
This PR is part of https://github.com/facebook/react-native/issues/34872
This PR extracts UnusedModuleInterfaceParserError exception to throwIfUnusedModuleInterfaceParserError inside an error-utils.js file.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal] [Changed] - Extracted UnusedModuleInterfaceParserError exception to throwIfUnusedModuleInterfaceParserError function

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

Test Plan:
yarn jest react-native-codegen
Added unit case in error-utils-test.js file
<img width="1173" alt="Screenshot 2022-10-11 at 1 56 50 PM" src="https://user-images.githubusercontent.com/87412080/195039924-5a73283b-a8cf-41a5-bcc4-9f619d381240.png">

Reviewed By: dmytrorykun

Differential Revision: D40296568

Pulled By: cipolleschi

fbshipit-source-id: b5ee4520db9c70a57c0c666d26ff3f63f17e9a59
2022-10-14 03:09:51 -07:00
Mohit Charkha ab22e3a834 Extracted MoreThanOneModuleRegistryCallsParserError exception to throwIfMoreThanOneModuleRegistryCalls inside error-utils.js (#34921)
Summary:
This PR is part of https://github.com/facebook/react-native/issues/34872
This PR extracts MoreThanOneModuleRegistryCallsParserError exception to throwIfMoreThanOneModuleRegistryCalls inside an error-utils.js file

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal] [Changed] - Extracted MoreThanOneModuleRegistryCallsParserError exception to throwIfMoreThanOneModuleRegistryCalls function

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

Test Plan:
yarn jest react-native-codegen
Added unit case in the `error-utils-test.js` file

<img width="936" alt="Extracted MoreThanOneModuleRegistryCallsParserError Test" src="https://user-images.githubusercontent.com/86604753/194876724-8beec16d-4b88-4685-b8a7-a2c89208378a.png">

Reviewed By: NickGerleman

Differential Revision: D40296527

Pulled By: cipolleschi

fbshipit-source-id: 8c0d2854f42918b61ce8569cbfbaee5e90b21398
2022-10-14 03:09:51 -07:00
Gabriel Donadel Dall'Agnol c9338c4597 chore: Extract codegen ModuleInterfaceNotFoundParserError in a separate function (#34922)
Summary:
This PR extracts the codegen `ModuleInterfaceNotFoundParserError` exception into a separate function inside `error-utils.js` so that it can be used by both Flow and Typescript parsers as requested on https://github.com/facebook/react-native/issues/34872. This also adds unit tests to the new `throwIfModuleInterfaceNotFound` function.

## Changelog

[Internal] [Changed] - Extract codegen `ModuleInterfaceNotFoundParserError` in a separate function that can de used by Flow and TypeScript parsers

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

Test Plan:
Run `yarn jest react-native-codegen` and ensure CI is green

![image](https://user-images.githubusercontent.com/11707729/194876017-8e98e3d2-4518-4cbe-b7f0-b77a54060b1e.png)

Reviewed By: dmytrorykun

Differential Revision: D40296533

Pulled By: cipolleschi

fbshipit-source-id: 205469b15337f6c3847936a6ef5427b5a9e08665
2022-10-14 03:09:51 -07:00
Vinay Harwani 2934399edd Extracted TypeDeclarationMap from flow and typescript to a common file parsers/utils.js (#34951)
Summary:
This PR is a part of https://github.com/facebook/react-native/issues/34872.
This PR extracts TypeDeclarationMap type from flow and typescript to a common file parsers/utils.js and updates all imports.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal] [Changed] - Extracted TypeDeclarationMap from flow and typescript to a common file parsers/utils.js.

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

Test Plan:
yarn jest react-native-codegen
<img width="1129" alt="Screenshot 2022-10-12 at 12 13 48 PM" src="https://user-images.githubusercontent.com/87412080/195270569-fc077863-7e51-49e8-92ef-f3991f838d6a.png">

Reviewed By: NickGerleman

Differential Revision: D40296917

Pulled By: cipolleschi

fbshipit-source-id: d073daf0aadc291d5f9d00c003f0161af9e11319
2022-10-13 02:41:28 -07:00
Gabriel Donadel Dall'Agnol 305f7c3352 chore: Extract codegen case 'Stringish' into a single emitStringish function (#34936)
Summary:
This PR extracts the content of the codegen case `'Stringish'` into a single `emitStringish` function inside the `parsers-primitives.js` file and uses it in both Flow and TypeScript parsers as requested on https://github.com/facebook/react-native/issues/34872. This also adds unit tests to the new `emitStringish` function.

## Changelog

[Internal] [Changed] - Extract the content of the case 'Stringish' into a single emitStringish function

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

Test Plan:
Run `yarn jest react-native-codegen` and ensure CI is green

![image](https://user-images.githubusercontent.com/11707729/194987664-b588b82b-a9e0-49a9-a3cc-a03cb0a230e6.png)

Reviewed By: cipolleschi

Differential Revision: D40255921

Pulled By: rshest

fbshipit-source-id: 9c08f81f12c93995bb6ba032fabcd6451b8dc7c1
2022-10-12 03:06:04 -07:00
youedd b3219fe345 Extract contents of the case 'VoidTypeAnnotation' into a single emitVoid function (#34932)
Summary:
Part of https://github.com/facebook/react-native/issues/34872

This PR:
- extracts the content of the case 'VoidTypeAnnotation' ([Flow](https://github.com/facebook/react-native/blob/b444f0e44e0d8670139acea5f14c2de32c5e2ddc/packages/react-native-codegen/src/parsers/flow/modules/index.js#L375-L377), [TypeScript](https://github.com/facebook/react-native/blob/00b795642a6562fb52d6df12e367b84674994623/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L410-L412)) into a single emitVoid function in the parsers-primitives.js file. Use the new function in the parsers.
- unit tests emitVoid function

## Changelog

[Internal] [Changed] - Extract contents of the case 'VoidTypeAnnotation' into a single emitVoid function

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

Test Plan:
` yarn jest react-native-codegen`

<img width="957" alt="image" src="https://user-images.githubusercontent.com/19575877/194931977-d5cfc5f5-c9db-498d-9e5c-ae40a38d3623.png">

Reviewed By: cipolleschi

Differential Revision: D40239730

Pulled By: rshest

fbshipit-source-id: 16a9555223cacbb3b9916fd469bd63f83db33f18
2022-10-12 03:06:04 -07:00
Marco Fiorito fd4451ecfa Chore/extract codegen case object to parser primitives (#34926)
Summary:
Part of https://github.com/facebook/react-native/issues/34872

This PR extracts the content of the case 'Object' ([Flow](https://github.com/facebook/react-native/blob/b444f0e44e0d8670139acea5f14c2de32c5e2ddc/packages/react-native-codegen/src/parsers/flow/modules/index.js#L365-L367), [TypeScript](https://github.com/facebook/react-native/blob/00b795642a6562fb52d6df12e367b84674994623/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L400-L402)) into a single emitObject function in the parsers-primitives.js file. Use the new function in the parsers.

## Changelog

[Internal] [Changed] - Extract contents of the case 'Object' into a single emitObject function

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

Test Plan: <img width="276" alt="image" src="https://user-images.githubusercontent.com/18408823/194892107-1da9d6e5-c659-47f9-8597-ff4a4b7710ca.png">

Reviewed By: rshest

Differential Revision: D40231670

Pulled By: cipolleschi

fbshipit-source-id: db6a61427c8c020d48be5317b094f136842b62ca
2022-10-11 15:17:13 -07:00
MaeIg 38fcafe623 Extract the function createParserErrorCapturer into a single function in the parsers/utils.js file (#34934)
Summary:
This PR aims to reduce code duplication by extracting `createParserErrorCapturer` function from the flow and typescript folders into a shared parsers/utils.js file. It is a task of https://github.com/facebook/react-native/issues/34872:
> Extract the function createParserErrorCapturer ([Flow](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/flow/utils.js#L122-L143) [TypeScript](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/typescript/utils.js#L114-L135)) into a single function in the parsers/utils.js file and replace its invocation with this new function.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[Internal] [Changed] - Extract the function createParserErrorCapturer into a single function in the parsers/utils.js file

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

Test Plan:
yarn flow:
<img width="628" alt="image" src="https://user-images.githubusercontent.com/40902940/194948886-d6763e39-ea07-4004-86cc-5287c4783012.png">

yarn lint:
<img width="509" alt="image" src="https://user-images.githubusercontent.com/40902940/194948916-3e54afa5-7e0b-4a61-ac18-8ec306d8c6d4.png">

yarn jest react-native-codegen:
<img width="386" alt="image" src="https://user-images.githubusercontent.com/40902940/194948966-d1e5b12e-02ab-4d53-a4bf-6abaf4d70fbe.png">

Reviewed By: cipolleschi

Differential Revision: D40256048

Pulled By: cipolleschi

fbshipit-source-id: 098519a17d6e3128d236c639b246a706f9dbf66d
2022-10-11 05:24:25 -07:00
Antoine Doubovetzky 966f3cdea3 extract emitPromise from parsers modules to shared parsers-primitives (#34935)
Summary:
This PR is a task from https://github.com/facebook/react-native/issues/34872:
> Extract the content of the case 'Promise' ([Flow](https://github.com/facebook/react-native/blob/b444f0e44e0d8670139acea5f14c2de32c5e2ddc/packages/react-native-codegen/src/parsers/flow/modules/index.js#L90-L97), [TypeScript](https://github.com/facebook/react-native/blob/00b795642a6562fb52d6df12e367b84674994623/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L197-L205)) into a single emitPromise function in the parsers-primitives.js file. Use the new function in the parsers.

Note that this PR should be merged after https://github.com/facebook/react-native/pull/34933

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal] [Changed] - Extract contents of the case 'Promise' into a single emitPromise function inside parsers-primitives

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

Test Plan: I tested using jest and flow commands.

Reviewed By: cipolleschi

Differential Revision: D40257033

Pulled By: cipolleschi

fbshipit-source-id: 0246f43c6b688629e2de1259e7f535c2cf6dd0a4
2022-10-11 05:22:59 -07:00
Antoine Doubovetzky 29e5655dee extract assertGenericTypeAnnotationHasExactlyOneTypeParameter to parsers-commons (#34933)
Summary:
This PR is a task from https://github.com/facebook/react-native/issues/34872:
> Extract the function assertGenericTypeAnnotationHasExactlyOneTypeParameter ([Flow](https://github.com/facebook/react-native/blob/b444f0e44e0d8670139acea5f14c2de32c5e2ddc/packages/react-native-codegen/src/parsers/flow/modules/index.js#L441) [TypeScript](https://github.com/facebook/react-native/blob/00b795642a6562fb52d6df12e367b84674994623/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L476)) into a single function in the parsers-common.js file and replace its invocation with this new function.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal] [Changed] - Extract assertGenericTypeAnnotationHasExactlyOneTypeParameter from the flow and typescript folders to parsers-commons

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

Test Plan: I tested using jest and flow commands.

Reviewed By: cipolleschi

Differential Revision: D40257022

Pulled By: cipolleschi

fbshipit-source-id: 609972914deade9afdd1c0cf1e17be1c08c1d37b
2022-10-11 05:22:59 -07:00
MaeIg 1fc27c4cba Extract TypeAlias logic of translateTypeAnnotation from the flow and typescript folders in parsers-primitives (#34918)
Summary:
This PR aims to reduce code duplication by extracting `typeAliasResolution` logic from the flow and typescript folders into a shared parsers-primitives file. It is a task of https://github.com/facebook/react-native/issues/34872:
> Wrap the TypeAlias resolution lines ([Flow](https://github.com/facebook/react-native/blob/b444f0e44e0d8670139acea5f14c2de32c5e2ddc/packages/react-native-codegen/src/parsers/flow/modules/index.js#L321-L362), [TypeScript](https://github.com/facebook/react-native/blob/00b795642a6562fb52d6df12e367b84674994623/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L356-L397)) in a proper typeAliasResolution function in the parsers-primitives.js files and replace those lines with the new function.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[Internal] [Changed] - Extract TypeAlias logic of translateTypeAnnotation from the flow and typescript folders in parsers-primitives

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

Test Plan:
All tests are passing, with `yarn jest react-native-codegen`:
<img width="930" alt="image" src="https://user-images.githubusercontent.com/40902940/194835192-49478b1c-3e04-40f9-b6f3-e26491f272ab.png">

Reviewed By: rshest

Differential Revision: D40223495

Pulled By: rshest

fbshipit-source-id: c74b68385e59497b6a8eaa56b96a001ef447a2cd
2022-10-10 10:47:40 -07:00
Jesse Katsumata cb3a5cc691 Add unit test for common parsers method (#34915)
Summary:
This PR is part of https://github.com/facebook/react-native/issues/34872
This PR adds unit test for method that were refactored into parsers-commons.js in codegen in https://github.com/facebook/react-native/issues/34898

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal] [Changed] - Add unit test for common parsers method

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

Test Plan: `yarn jest react-native-codegen`

Reviewed By: cipolleschi

Differential Revision: D40219036

Pulled By: cipolleschi

fbshipit-source-id: 2fb666c016f7822feaf2156d23ce7ffb9572c756
2022-10-10 04:23:30 -07:00
Antoine Doubovetzky 3ab7ef24a7 extract emitDouble from parsers modules to shared parsers-primitives (#34913)
Summary:
Part of https://github.com/facebook/react-native/issues/34872

This PR extracts the content of the case 'Double' ([Flow](https://github.com/facebook/react-native/blob/b444f0e44e0d8670139acea5f14c2de32c5e2ddc/packages/react-native-codegen/src/parsers/flow/modules/index.js#L202-L204), [TypeScript](https://github.com/facebook/react-native/blob/00b795642a6562fb52d6df12e367b84674994623/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L1235-L237)) into a single emitDouble function in the parsers-primitives.js file. Use the new function in the parsers.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal] [Changed] - Extract contents of the case 'Double' into a single emitDouble function inside parsers-primitives

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

Test Plan: I tested using jest and flow commands.

Reviewed By: cipolleschi

Differential Revision: D40216018

Pulled By: cipolleschi

fbshipit-source-id: bc2aaa7636fbd2f6c861e4d87e394d0e4875a4a5
2022-10-10 04:23:30 -07:00
MaeIg 5f05b07d02 Extract RootTag case of translateTypeAnnotation from the flow and typescript folders in parsers-primitives (#34901)
Summary:
This PR aims to reduce code duplication by extracting `emitRootTag` logic from the flow and typescript folders into a shared parsers-primitives file. It is a task of https://github.com/facebook/react-native/issues/34872:
> Extract the content of the case 'RootTag' (Flow TypeScript) into a single emitRootTag function in the parsers-primitives.js file. Use the new function in the parsers.

~~Note that https://github.com/facebook/react-native/issues/34898 should be merged first. I rebased on it's branch.~~

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[Internal] [Changed] - Extract RootTag case of translateTypeAnnotation from the flow and typescript folders in parsers-primitives

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

Test Plan:
All tests are passing, with `yarn jest react-native-codegen`:
<img width="934" alt="image" src="https://user-images.githubusercontent.com/40902940/194777150-6136c1b6-11f8-4e21-829b-fda418b6925c.png">

Reviewed By: cipolleschi

Differential Revision: D40212553

Pulled By: cipolleschi

fbshipit-source-id: eadbbfb5cf6dfa6c966f4c08a5d9372a3470b621
2022-10-10 04:23:30 -07:00
Tarun Chauhan 7b345bca55 Extract module/errors into a shared file (#34896)
Summary:
This PR reduces code duplication by extracting all the errors in the module/errors into a single parsers/errors.js file. All the errors must drop the corresponding Flow or Typescript token in the name and take an extra language parameter in the constructor. Also, rename the hasteModuleName parameter to nativeModuleName.

Part of https://github.com/facebook/react-native/issues/34872

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal] [Changed] - Extract all the parsers errors in the module/errors into a single parsers/errors.js file

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

Test Plan:
run ```yarn jest react-native-codegen``` and check all test case passes.

<img width="793" alt="image" src="https://user-images.githubusercontent.com/34857453/194545577-cf2d980b-b6b7-4f93-b13e-2e45d92dceab.png">

Reviewed By: rshest

Differential Revision: D40176486

Pulled By: rshest

fbshipit-source-id: b33ae49b2bcceeffd307370ee5e3b24a9e1bb340
2022-10-10 04:20:22 -07:00
Riccardo Cipolleschi d7c41361dd Add ImageSource and ImageRequest to generate custom NativeState (#34910)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/34910

This Diff adds supports on the CustomState generation for ImageSource and ImageRequests, to enable NativeComponents to use the ImageSource loading provided by React Native.

To achieve this, I also had to fox some errors in the imports and to introduce some functions to decorate parameters.

This diff also introduces the tests for thise additional types in both generators and parsers.

## Changelog
[General][Added] - add support for ImageSource and ImageRequest in the State.

Reviewed By: cortinico

Differential Revision: D39884889

fbshipit-source-id: ae3d2d51dfe6a4fe688dc78fec83f428beb8d443
2022-10-10 02:51:06 -07:00
Riccardo Cipolleschi 7490ad4a21 Generate Custom Native State (#34796)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/34796

This diff introduces the generation of custom native states using basic types as we do with the Props.

To make it work, the custom types are already writte in the Props.h file, therefore the State.h file must import that other file to have access to the required types.

This diff adds and updates the tests for the State.

## Changelog
[General][Added] - Generate custom Native State

Reviewed By: cortinico

Differential Revision: D39816763

fbshipit-source-id: 42d1aa9a6df23145f4a46ae8ccfb43d81fa651fb
2022-10-10 02:51:06 -07:00
Youssef Eddibili 54fc62cda7 Extract contents of the case 'NumberTypeAnnotation' into a single emitNumber function (#34908)
Summary:
Part of https://github.com/facebook/react-native/issues/34872

This PR:
- extracts the content of the case 'NumberTypeAnnotation' ([Flow](https://github.com/facebook/react-native/blob/b444f0e44e0d8670139acea5f14c2de32c5e2ddc/packages/react-native-codegen/src/parsers/flow/modules/index.js#L370-L372), [TypeScript](https://github.com/facebook/react-native/blob/00b795642a6562fb52d6df12e367b84674994623/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L405-L407)) into a single emitNumber function in the parsers-primitives.js file, and uses the new function in the parsers
- unit tests emitNumber function

## Changelog

[Internal] [Changed] - Extract contents of the case 'NumberTypeAnnotation' into a single emitNumber function

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

Test Plan:
` yarn jest react-native-codegen`

<img width="935" alt="image" src="https://user-images.githubusercontent.com/19575877/194764122-44975a97-3acd-4f27-babe-ddcd58c3ec61.png">

Reviewed By: cipolleschi

Differential Revision: D40214542

Pulled By: cipolleschi

fbshipit-source-id: a7746d3f1dd5f127dc520c6156383b18e00281ec
2022-10-09 17:34:10 -07:00
Jesse Katsumata db8c11d392 Extract the content of the case 'Int32' (Flow, TypeScript) into a single emitInt32 function in the parsers-primitives.js file. (#34906)
Summary:
Part of https://github.com/facebook/react-native/issues/34872

Refactors emitInt32 in codegen parser module into a common parsers-primitive.js

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal] [Changed] - Extract the content of the case 'Int32' (Flow, TypeScript) into a single emitInt32 function

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

Test Plan:
Ran `yarn jest react-native-codegen`

<img width="690" alt="Screen Shot 2022-10-09 at 15 45 21" src="https://user-images.githubusercontent.com/6936373/194742142-801a89c8-f803-4e8d-9b05-cf6bda97ea19.png">

Reviewed By: cipolleschi

Differential Revision: D40212544

Pulled By: cipolleschi

fbshipit-source-id: 845e3758ab654edb972a8d8dc3cfa73464e2d49d
2022-10-09 13:34:38 -07:00
Tarun Chauhan 7a2e3468e9 Extract contents of the case 'BooleanTypeAnnotation' into a single emitBoolean function (#34907)
Summary:
Part of https://github.com/facebook/react-native/issues/34872

This PR extracts the content of the case 'BooleanTypeAnnotation' ([Flow](https://github.com/facebook/react-native/blob/b444f0e44e0d8670139acea5f14c2de32c5e2ddc/packages/react-native-codegen/src/parsers/flow/modules/index.js#L365-L367), [TypeScript](https://github.com/facebook/react-native/blob/00b795642a6562fb52d6df12e367b84674994623/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L400-L402)) into a single emitBoolean function in the parsers-primitives.js file. Use the new function in the parsers.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal] [Changed] - Extract contents of the case 'BooleanTypeAnnotation' into a single emitBoolean function

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

Test Plan:
Run ```yarn jest react-native-codegen```

<img width="803" alt="image" src="https://user-images.githubusercontent.com/34857453/194751101-3b1a619e-332a-43a9-bfa3-35f5869d7c5f.png">

Reviewed By: cipolleschi

Differential Revision: D40212518

Pulled By: cipolleschi

fbshipit-source-id: 9c1462c1e51a1836f963866dc4101f081898df00
2022-10-09 13:34:38 -07:00
Gabriel Donadel Dall'Agnol 7227bdec8e chore: Extract codegen ParserError from flow and typescript into a common file (#34874)
Summary:
This PR extracts the `ParserError` class from the `error.js` files from the flow and typescript folders into a single file in their parent folder in order to reduce the amount of duplicated code as requested on https://github.com/facebook/react-native/issues/34872

## Changelog

[Internal] [Changed] - Extract codegen `ParserError` from flow and typescript folders into a common file

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

Test Plan:
Run `yarn jest react-native-codegen` and ensure CI is green

![image](https://user-images.githubusercontent.com/11707729/194135137-bf0fc82d-220b-4509-b1bb-1e7dae925efe.png)

Reviewed By: cipolleschi

Differential Revision: D40133301

Pulled By: cipolleschi

fbshipit-source-id: 060571cf993672a9d03003e1a1a7c2aa2f381123
2022-10-09 03:17:28 -07:00
Antoine Doubovetzky 24efebf83d Extracts modules/utils.js files from the flow and typescript folders in parsers-commons (#34898)
Summary:
This PR is a task from https://github.com/facebook/react-native/issues/34872
_Extract the modules/utils.js from the flow and typescript folders in a shared parsers-commons.js file. Then, have the two parsers use the same wrapModuleSchema function for modules._
(`wrapModuleSchema` is a copy-paste mistake, in this case it is `wrapNullable` and `unwrapNullable`)

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal] [Changed] - Extracts Codegen's modules/utils.js files from the flow and typescript folders in parsers-commons

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

Test Plan:
I ran `yarn jest react-native-codegen`:
<img width="775" alt="Capture d’écran 2022-10-07 à 21 29 48" src="https://user-images.githubusercontent.com/17070498/194639515-a446c2cf-daf3-43a1-9833-cd546ca5865e.png">

Reviewed By: cipolleschi

Differential Revision: D40193740

Pulled By: cipolleschi

fbshipit-source-id: 02cbacc215fe5dd9bdd0839d8796587ab2821906
2022-10-08 08:22:58 -07:00
Tarun Chauhan 35556dba60 Extract modules/schema.js from flow and TS folders to a shared file (#34879)
Summary:
This PR reduces code duplication by ```extracting the modules/schema.js from the flow and typescript folders in a shared parsers-commons.js file. Then, have the two parsers use the same wrapModuleSchema function for modules``` as part of https://github.com/facebook/react-native/issues/34872

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal] [Changed] - Extracts the modules/schema.js from the flow and typescript folders in a shared file.

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

Test Plan:
run ```yarn jest react-native-codegen```
<img width="788" alt="image" src="https://user-images.githubusercontent.com/34857453/194232470-3ae3b99a-2556-48da-aac6-20ffc95f90a0.png">

Reviewed By: robhogan

Differential Revision: D40143266

Pulled By: robhogan

fbshipit-source-id: 417a5456c8099ad2761617e2be7cf8306c7d9ec4
2022-10-07 09:20:48 -07:00
Zihan Chen (MSFT) c4f9556f7e Make yarn and yarn jest react-native-codegen works on Windows with git (#34854)
Summary:
A few fixings to make `yarn jest react-native-doegen` works on Windows:

- ~~Add a `.gitignore` file to tell git not to track generated/temporary files.~~
- There is no `rm` on Windows, change it to `rimraf`.

I have been using it in the last 3 months and it works perfectly on Windows, otherwise I could not even build the code in my laptop.

## Changelog

[General] [Changed] - Make `yarn` and `yarn jest react-native-codegen` works on Windows with git

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

Test Plan: `yarn jest react-native-codegen` passed

Reviewed By: cortinico

Differential Revision: D40059524

Pulled By: cortinico

fbshipit-source-id: e3cde2506c7d18c2b580099257637b90f4cb328c
2022-10-07 08:04:02 -07:00
Riccardo Cipolleschi 7680bdeb4f Implement filtering for platform specific spec files
Summary:
This diff helps the library maintainer to keep their spec file platform specific if some specs make no sense in one platform or in the other.

We are filtering the spec files when we need to create the Schema.

The diff modifies also the call sites in the `scripts` (for iOS) and in the `gradle-plugin` (for Android).

It also adds tests for the new functions in the CLI.

The change is completely additive and it should not change any pre-existing behaviour.

## Changelog
[General][Added] - Add support for platform-specific specs

Reviewed By: cortinico

Differential Revision: D40008581

fbshipit-source-id: b7fcf6d38f85fe10e4e00002d3c6f2910abdbe35
2022-10-07 03:21:17 -07:00
Zihan Chen (MSFT) 00b795642a Refactor in turbo module TypeScript codegen: process (T), T|U, T|undefined and related stuff in a central place (#34814)
Summary:
`TSParenthesizedType`, `TSUnionType`, `TSNullKeyword`, `TSUndefinedKeyword`, `TSVoidKeyword` etc are repeatly processed in so many places. In this change I put them in a new file `parseTopLevelType.js`, and everyone call that file, all repeat implementation are deleted.

The `parseTopLevelType` function will look into a type consisted by the above types in any possible combination (but still very easy to do), and tell you if a type is nullable, or if there is a default value, and what is the real type with all noises removed.

Array types and union types are processed in component twice, for property of array, and property of nested arrays (`componentsUtils.js`). They are extracted into single functions.

## Changelog

[General] [Changed] - Refactor in turbo module TypeScript codegen: process `(T)`, `T|U`, `T|undefined` and related stuff in a central place

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

Test Plan: `yarn jest react-native-codegen` passed

Reviewed By: yungsters, sammy-SC

Differential Revision: D40094373

fbshipit-source-id: f28e145bc4e7734be9036815ea425d820eadb8f0
2022-10-07 03:13:38 -07:00
Nicola Corti 73bcedb903 Expose rrc_image to consuming builds
Summary:
This change will expose the rrc_image module to be consumed via Prefab by user projects. This is needed as part of a change of the codegen to support custom states.

Changelog:
[Internal] [Changed] - Expose rrc_image to consuming build

Reviewed By: cipolleschi

Differential Revision: D40098541

fbshipit-source-id: 2e07d8b19f53ba93920009603c95a43b01f131eb
2022-10-06 16:41:46 -07:00
Nicola Corti e13aaaa9a4 Expose react_render_imagemanager to consuming builds
Summary:
This change will expose the `react_render_imagemanager` module to be consumed via Prefab by user projects. This is needed as part of a change of the codegen to support custom states.

Changelog:
[Internal] [Changed] - Expose react_render_imagemanager to consuming build

Reviewed By: cipolleschi

Differential Revision: D40022929

fbshipit-source-id: ece47503b11a641067ae6db82f1d69b244c9c5be
2022-10-06 16:41:46 -07:00
Pieter De Baets b9a03ce197 Fix crash when exporting type of existing variable
Summary:
When using flow syntax like this, the parser would throw an error.

```
const foo = new ClassInstance();
export type {foo};
```

Changelog: [Internal]

Reviewed By: christophpurrer

Differential Revision: D39850098

fbshipit-source-id: 28a7748892559c2c4a0fb8afa8612cbeb5568058
2022-10-03 04:15:04 -07:00
Riccardo Cipolleschi f3c98c5fa2 Handle properly negative values in TS parser (#34800)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/34800

The TypeScript parser was not handling negative default values properly. The reason why is because the AST for those values is structurally different and wraps them in a `UnaryExpression` with the `-` operator.

This Diff adds the support for those default values and it also add some tests in both Flow and TS.

## Changelog
[General][Fixed] - Properly parse negative values

Reviewed By: cortinico

Differential Revision: D39847784

fbshipit-source-id: 95fc5768987477c540a54a7c4e4ff785d7a1e5d7
2022-09-30 04:02:48 -07:00
Zihan Chen (MSFT) 8dc6bec719 Fix interface support in turbo module TypeScript codegen (component only) (#34778)
Summary:
Interface was supported in component, but it only allows interfaces in limited cases.

In this change, I extended interface support to all places where object literal type is supported.

I also refactor the code so that properties and events are able to share the same implementation.

In order not to mess up the diff, I noticed that implementations are repeated in processing array properties and non-array properties. But I leave it without refactoring. I will do it in future PRs.

I also commented potential problems I found in the code.

## Changelog

[General] [Changed] - Fix interface support in turbo module TypeScript codegen (component only)

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

Test Plan: `yarn jest react-native-codegen` passed

Reviewed By: cortinico

Differential Revision: D39809230

Pulled By: cipolleschi

fbshipit-source-id: cfb51ce915249b5abceafee1c08b7e5762d03519
2022-09-27 06:59:57 -07:00
Riccardo Cipolleschi bbb2fb212d Parse custom NativeState in TypeScript (#34786)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/34786

This diff is the TS equivalent of D39686251.
It introduces the possibility to parse a custom Native State in Typescript.

The parsing follows the exact same rules as props, as initial heuristic. This should allow enough customization for the developers who needs a custom state.

Currently, we only support using `interface` for the state and the interface must contain the `NativeState` string in its name.

This diff introduces also tests for the TypeScript parser and it aligns the tests between Flow and TS.

## Changelog

[General][Added] - Implement custom Native State parsing in TypeScript

Reviewed By: cortinico

Differential Revision: D39811476

fbshipit-source-id: 1e1b86b50b9632c13157ff6c8115f5ebcbada643
2022-09-26 07:33:07 -07:00
Riccardo Cipolleschi 925b15351f Parse custom NativeState in Flow (#34753)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/34753

This Diff introduce a the capability to parse custom NativeStates in Flow. To achieve this I also had to define the CodegenSchema.

The parsing follows the exact same rules as props, as initial heuristic. This should allow enough customization for the developers who needs a custom state.

There is only a case I was not able to make it work that is STATE_ALIASED_LOCALLY, from the fixtures. I don't know how diffuse it is and I think we can live with some workarounds for the time being.

This diff also adds tests for the custom Native State Flow Parser.

## Changelog
[General][Added] - Implement custom Native State parsing in Flow

Reviewed By: cortinico

Differential Revision: D39686251

fbshipit-source-id: 446997a39b33b7e9351d5ba12cecaeff33df4d16
2022-09-26 07:33:07 -07:00
Zihan Chen (MSFT) 205cc9bc3b Handle (T) and undefined properly in turbo module component codegen (#34693)
Summary:
In `buildEventSchema` and `buildPropSchema`, they check into property types to see if the given property could be converted into an event schema or a property schema. The original implementation only handles limited cases, I refactor them and make them easier to maintain.

In `getPropertyType` in `events.js`, it handles `(T)` at a wrong place, fixed.

In `getPropertyType` in `props.js`, it doesn't handle `(T)`, fixed.

And I also fixed some other issues to make the codegen reports error better.

There are many duplicated test cases that cover every piece of the code, I changed some of them so that it tests both original cases and new cases.

## Changelog

[General] [Changed] - Handle (T) and undefined properly in turbo module component codegen

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

Test Plan: `yarn jest` passed in `packages/react-native-codegen`

Reviewed By: NickGerleman

Differential Revision: D39647075

Pulled By: cipolleschi

fbshipit-source-id: 8e1df2b54aab37b7151d0bf74260e2eba0602777
2022-09-22 11:40:38 -07:00
Riccardo Cipolleschi b7add0aadb Always generate an EmptyNativeState (#34754)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/34754

This Diff is the second step of enabling the CodeGen to parse and generate a NativeState for the components.

The feature has been largely requested by the OSS community but it could be also helpful for people in Meta.

## Changelog
[General][Added] - Always generate an empty NativeState for Fabric Components

Reviewed By: cortinico

Differential Revision: D39696435

fbshipit-source-id: e24768af78f59696c0b4db009e8065bb5c89316b
2022-09-22 06:41:44 -07:00
Riccardo Cipolleschi 69f8cf14f0 Always generate the EventEmitters (#34750)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/34750

This Diff is the first step of enabling the CodeGen  to parse and generate a NativeState for the components.

The feature has been largely requested by the OSS community but it could be also helpful for people in Meta.

To allow the generation of custom `NativeState`, we first have to always generate a `ViewEventEmitter`: that's because the `ConcreteShadowNode` template lists the Generics with this order: `Name`, `Props`, `EventEmitter`, Others...
If we skip the `EventEmitters` and we put the `State`, React Native would think that the State is actually an `EventEmitter` and the build step will fail.

## Changelog
[General][Added] - Always generate a ViewEventEmitter for Fabric Components

Reviewed By: cortinico

Differential Revision: D39509869

fbshipit-source-id: 390cc146ef013baf1ed09d55a0182a5aeb5b9d9e
2022-09-22 06:41:44 -07:00
Gianluca Spada 2f6b2127d9 Fix: Codegen template error in RCTThirdPartyFabricComponentsProvider (#34738)
Summary:
When `GenerateRCTThirdPartyFabricComponentsProviderCpp.js` generates `RCTThirdPartyFabricComponentsProvider.mm` an edge case happens in the following situation:
- The same library exports multiple modules with one component each (i.e. one component per file);
- The **first component** is excluded for iOS via the `excludedPlatforms` property in *codegenNativeComponent*.

A "loose" comma appears in the generated template, breaking the code.

```c++
Class<RCTComponentViewProtocol> RCTThirdPartyFabricComponentsProvider(const char *name) {
  static std::unordered_map<std::string, Class (*)(void)> sFabricComponentsClassMap = {
, // <-- the offending comma
    {"NativeComponent2", NativeComponent2Cls}, // rnmylibrary
  };
}
```

At some point, `GenerateRCTThirdPartyFabricComponentsProviderCpp.js` does not properly filter out empty arrays resulting from excluded components. This does not seem to be a problem when the excluded component is not the first being processed, as the comma gets added at the end of the previous line, after the comment with the name of the library.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[iOS] [Fixed] - Fix error in the Codegen template for ThirdPartyFabricComponentsProvider

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

Test Plan:
<!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes the user interface. -->

This is the schema that leads to the bug. Notice that the first component was excluded for iOS.
```json
{
  "modules": {
    "ComponentFile1": {
      "type": "Component",
      "components": {
        "NativeComponent1": {
          "excludedPlatforms": ["iOS"]
          "extendsProps": [
            {
              "type": "ReactNativeBuiltInType",
              "knownTypeName": "ReactNativeCoreViewProps"
            }
          ],
          "events": [],
          "props": [],
          "commands": []
        }
      }
    },
    "ComponentFile2": {
      "type": "Component",
      "components": {
        "NativeComponent2": {
          "extendsProps": [
            {
              "type": "ReactNativeBuiltInType",
              "knownTypeName": "ReactNativeCoreViewProps"
            }
          ],
          "events": [],
          "props": [],
          "commands": []
        }
      }
    }
  }
```

`GenerateRCTThirdPartyFabricComponentsProviderCpp.js` should generate a template without the comma in the wrong position (before NativeComponent2).

I also added an additional test case to cover this problem. All the other tests passed.

Reviewed By: sammy-SC

Differential Revision: D39686573

Pulled By: cipolleschi

fbshipit-source-id: 6054464d024218eb0b2e02974aa5cc7c8aebbbc9
2022-09-21 04:13:12 -07:00