Commit Graph

686 Commits

Author SHA1 Message Date
Gabriel Donadel Dall'Agnol 87d65803ab chore: Extract codegen case 'Float' into a single emitFloat function (#35124)
Summary:
## Summary

This PR extracts the content of the codegen case `'Float'` into a single `emitFloat` 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 `emitFloat` function.

## Changelog

[Internal] [Changed]  - Extract the content of the case 'Float' into a single emitFloat function

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

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

![image](https://user-images.githubusercontent.com/11707729/198704932-202e2cd7-5b04-4009-b47e-b4999fee6c98.png)

Reviewed By: rshest

Differential Revision: D40828746

Pulled By: cipolleschi

fbshipit-source-id: 9c7cecf7268f16aaef29065c1983ad9a4dd18dbe
2022-10-29 06:40:54 -07:00
Lorenzo Sciandra cd25fb3240 chore(deps): add wanted dependencies to remove yarn warnings (#35122)
Summary:
This is take 2 of this https://github.com/facebook/react-native/pull/35088, see this comment for why https://github.com/facebook/react-native/pull/35088#issuecomment-1295091902

I wanted to start working on a thing but this barrage of warnings was very annoying so ended up doing this instead: a very small PR to take care of some warnings during yarn install.

It doesn't change anything (the versions are the ones already used all around the repo), just makes yarn happier.

## 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
-->

[General] [Fixed] - add wanted dependencies to remove yarn warnings

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

Test Plan:
### Before

<img width="1920" alt="Screenshot 2022-10-26 at 10 53 32" src="https://user-images.githubusercontent.com/16104054/197996489-f463be29-b35b-45cc-9d9c-2d176579fb7d.png">

### After

<img width="947" alt="Screenshot 2022-10-26 at 10 52 19" src="https://user-images.githubusercontent.com/16104054/197996505-3d60b319-006b-45ab-83bf-2f431272fdcd.png">

Reviewed By: cortinico

Differential Revision: D40804260

Pulled By: rshest

fbshipit-source-id: 86af14c885d6d63a0d60bb85f204d17d8757f72a
2022-10-28 13:01:48 -07:00
Antoine Doubovetzky 8c69b6cf78 Extract throwIfUnsupportedFunctionParamTypeAnnotationParserError function (#35057)
Summary:
This PR is a task from https://github.com/facebook/react-native/issues/34872:

> Extract the UnsupportedFunctionParamTypeAnnotationParserError in its own throwing function (if it does not exists already) and reuse that function passing a proper type. Then, refactor the code using a dictionary and avoiding the three different ifs in both 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 UnsupportedFunctionParamTypeAnnotationParserError in its own throwing function in error-utils

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

Reviewed By: lunaleaps

Differential Revision: D40721099

Pulled By: cipolleschi

fbshipit-source-id: af5e4cd275d0049047d35660559b94a27e660e40
2022-10-28 07:21:15 -07:00
youedd 0627cd69cd Refactor translate UniontypeAnnotation (#35050)
Summary:
Part of https://github.com/facebook/react-native/issues/34872
> [Assigned to youedd] This task is more advanced than the others Create a function to unify the [unionType](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/flow/modules/index.js#L372-L396) and the [TSUnionType](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L407-L431). This task may share some logic from the previous task. The function should accept a ParserType parameter to implement the proper logic to extract the memberType variable. Ideally, we should create a couple of supporting functions to implement those logics.

## 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] - Refactor translate UniontypeAnnotation

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

Test Plan:
`yarn jest react-native-codegen`
![image](https://user-images.githubusercontent.com/19575877/197334084-2daeed7e-8e87-4140-b8c3-07f2de3f0496.png)

Reviewed By: cortinico

Differential Revision: D40637299

Pulled By: cipolleschi

fbshipit-source-id: 1490001a3398c3af79d465c40de3c3687f058523
2022-10-26 10:02:01 -07:00
dhruvtailor7 cba56eadd2 Extract getConfigType function to parsers/utils.js (#35035)
Summary:
This PR is part of https://github.com/facebook/react-native/issues/34872.
This PR contains two changes, extracting the visitor object and then factoring out the `getConfigType()` function to the `parsers/utils.js` file. Then we can reuse the same function in both flow and typescript by passing the extracted visitor object.

## Changelog

[Internal] [Changed] - Extract visitor object in the same file and factor out `getConfigType()` to `parsers/utils.js`.

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

Test Plan: Output of `yarn jest react-native-codegen` ensures all passed test cases

Reviewed By: cortinico

Differential Revision: D40548855

Pulled By: cipolleschi

fbshipit-source-id: 310b8565322a4e4800a3fffc67479a9dfa45d620
2022-10-26 10:02:01 -07:00
Benny Singer cf5addf423 Revert D40716713: chore(deps): add wanted dependencies to remove yarn warnings
Differential Revision:
D40716713 (https://github.com/facebook/react-native/commit/8422c5315caf5cf696791a5ad49ed0fbd37ef9df)

Original commit changeset: eeb95a91c6cd

Original Phabricator Diff: D40716713 (https://github.com/facebook/react-native/commit/8422c5315caf5cf696791a5ad49ed0fbd37ef9df)

fbshipit-source-id: e85f111e7da0381e09f8a23d3bd0d553b3a7c4a9
2022-10-26 07:22:28 -07:00
Lorenzo Sciandra 8422c5315c chore(deps): add wanted dependencies to remove yarn warnings (#35088)
Summary:
I wanted to start working on a thing but this barrage of warnings was very annoying so ended up doing this instead: a very small PR to take care of some warnings during yarn install.

It doesn't change anything (the versions are the ones already used all around the repo), just makes yarn happier.

Also, while doing that I found a dependency that was lying there unused for 2 years so took care of it.

## 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
-->

[General] [Fixed] - add wanted dependencies to remove yarn warnings

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

Test Plan:
### Before

<img width="1920" alt="Screenshot 2022-10-26 at 10 53 32" src="https://user-images.githubusercontent.com/16104054/197996489-f463be29-b35b-45cc-9d9c-2d176579fb7d.png">

### After

<img width="947" alt="Screenshot 2022-10-26 at 10 52 19" src="https://user-images.githubusercontent.com/16104054/197996505-3d60b319-006b-45ab-83bf-2f431272fdcd.png">

Reviewed By: jacdebug

Differential Revision: D40716713

Pulled By: robhogan

fbshipit-source-id: eeb95a91c6cdf37edfe868fefe4ba04aebe500ec
2022-10-26 06:42:50 -07:00
Christoph Purrer 745f3ee8c5 react-native-code-gen Add Enum Type support for iOS/Android TurboModules
Summary:
Adding enum support to Android/iOS generated code

Changelog:
[General][Added] - react-native-code-gen Add Enum Type support for iOS/Android TurboModules

Reviewed By: javache

Differential Revision: D38967241

fbshipit-source-id: d8bb3019dab198e16905a6422e877cd751119122
2022-10-25 08:27:47 -07:00
Riccardo Cipolleschi 5940d25cc1 Create the Parser interface (#35036)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35036

This diff is the base to create a polimorphic behavior for TypeScript and Flow parser. This type will allow to share a lot of code between the parsers and also to keep their differences a part.

It will be the base diff/PR for further tasks in the Codegen umbrella Issue

## Changelog:
[General][Added] - Parser interface to divide parser logic.

Reviewed By: cortinico

Differential Revision: D40548707

fbshipit-source-id: e632ba52b00b43e50306e3a792a841e72e8c07f4
2022-10-25 05:01:19 -07:00
Sam Zhou 466ba91657 Implicit instantiation codemod
Summary: Changelog: [Internal]

Reviewed By: bradzacher

Differential Revision: D40543059

fbshipit-source-id: 4d10671d8f2734b47d2aa86646be7f543a174515
2022-10-20 19:06:09 -07:00
Zihan Chen (MSFT) affcfa7bde Refactor codegen: Dispatch props and events from a central place. (#34975)
Summary:
Refer to `In component, props and events pick properties from the component interface by themselves independently, I would like to reverse the direction, to have a function dispatching properties to props and events, to reduce duplicated code.
` in https://github.com/facebook/react-native/issues/34872

## Changelog

[General] [Changed] - Refactor codegen: Dispatch props and events from a central place.

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

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

Reviewed By: cortinico

Differential Revision: D40507917

Pulled By: cipolleschi

fbshipit-source-id: 71988877008ae11a01affd31b34bb3a3b88f96be
2022-10-20 12:06:50 -07:00
Jordan Brown 7884f6cfec Implicit instantiation codemod
Summary:
This diff adds explicit type arguments to polymorphic function calls that do not constrain their types. This codemod will reduce the error burden that will come in a future version of flow.

This specific diff was generated by running:
```
flow codemod annotate-implicit-instantiations --write .
flow --json --pretty | jq '.errors | .[] | .message | .[] | .loc |.source' | sort | uniq | sed -e 's/"//g' | xargs hg revert
hg st -n | xargs grep "generated" | sed -e 's/:.*//g' | xargs hg revert
arc f
```

So these are the codemod results that introduced no new errors and no generated files.

Changelog: [Internal]

drop-conflicts

Reviewed By: SamChou19815

Differential Revision: D40413074

fbshipit-source-id: 42b52719978f1098169662b503dbcfd8cefdad53
2022-10-19 10:25:09 -07:00
Marco Fiorito f628edc502 Chore/extract codegen parser more than one module exception (#34920)
Summary:
This PR is part of https://github.com/facebook/react-native/issues/34872
This PR extracts MoreThanOneModuleInterfaceParserError exception to a separate function inside an error-utils.js file

## Changelog

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

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

Test Plan: <img width="297" alt="image" src="https://user-images.githubusercontent.com/18408823/194859284-7d3ff330-c644-472e-9ae0-3b9444bc12e8.png">

Reviewed By: cortinico

Differential Revision: D40226575

Pulled By: cipolleschi

fbshipit-source-id: 01e581abfae1ffe40e92bed8c9bedd6fe09e1aab
2022-10-19 08:54:48 -07:00
Gabriel Donadel Dall'Agnol 376ffac759 chore: Export codegen parseFile function (#35000)
Summary:
This PR export the content of the `parseFile` into a parseFile function accepting a callback to buildSchema properly in `parsers/utils.js` as requested on https://github.com/facebook/react-native/issues/34872.

## Changelog

[Internal] [Changed] - Export ` parseFile` in to a `parseFile` function in `parsers/utils.js`

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

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

![image](https://user-images.githubusercontent.com/11707729/196051689-1b61838c-477c-4be5-8df0-9f5969fcf90d.png)

Reviewed By: cortinico

Differential Revision: D40424857

Pulled By: cipolleschi

fbshipit-source-id: a700033d674b8be8e1af942dedf73155ea3ca025
2022-10-19 01:38:28 -07:00
MaeIg 8f484c3a62 Extract the switch(configType) block from the buildSchema function into a new function in the parsers/utils.js file (#34992)
Summary:
This PR aims to extract  the switch(configType) block from the buildSchema function into a separate function in a shared file between typescript and flow. It is a task of https://github.com/facebook/react-native/issues/34872:
> This task is more advanced than the others. Extract the switch(configType) block ([Flow](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/flow/index.js#L82-L119), [TypeScript](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/typescript/index.js#L92-L129)) from the buildSchema function into a new function in the parsers/utils.js file and use it in the two functions. Note that the new function must accept some callbacks to wrapModule/ComponentSchema and to buildModule/ComponentSchema.

## 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 switch(configType) block from the buildSchema function into a new function in the parsers/utils.js file

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

Test Plan:
yarn flow:
<img width="548" alt="image" src="https://user-images.githubusercontent.com/40902940/195980663-a2d0e4bd-d2b8-464e-bbf5-3bcde553f7e8.png">

yarn lint:
<img width="521" alt="image" src="https://user-images.githubusercontent.com/40902940/195980675-a5c67d00-a822-46a8-8bd4-e1fe4f7fb698.png">

yarn jest react-native-codegen:
<img width="415" alt="image" src="https://user-images.githubusercontent.com/40902940/195980681-672e4447-4b33-43e8-a866-9e619ad332b1.png">

I added new tests:
<img width="621" alt="image" src="https://user-images.githubusercontent.com/40902940/195980703-8a68756a-45ad-4931-971f-f1e83ce16a96.png">

Reviewed By: cortinico

Differential Revision: D40429659

Pulled By: cipolleschi

fbshipit-source-id: 7e9875c129fee17c3cc5ef9c6f7990f39bfe2bf0
2022-10-19 01:38:28 -07:00
harshsiriah 32474367c2 Extracted UnsupportedFunctionReturnTypeAnnotationParserError to throwIfUnsupportedFunctionReturnTypeAnnotationParserError (#34965)
Summary:
This PR is part of https://github.com/facebook/react-native/issues/34872
This PR extracts `UnsupportedFunctionReturnTypeAnnotationParserError` exception to a separate function inside an `error-utils.js` file

## Changelog

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

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

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

<img width="939" alt="Screenshot 2022-10-13 at 11 46 54 AM" src="https://user-images.githubusercontent.com/86605635/195517350-dcb7a26d-434c-4e45-a174-ce82931073e5.png">

Reviewed By: dmytrorykun

Differential Revision: D40338048

Pulled By: cipolleschi

fbshipit-source-id: baa41e0e96c9e17a35f316433c8d80c9bf88d334
2022-10-19 01:38:28 -07:00
Ken Tominaga eda90e5181 Extract the content of the case 'StringTypeAnnotation' into a single … (#34981)
Summary:
This PR extracts the content of the codegen case 'String' into a single `emitString` 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 `emitString` function.

ref: https://github.com/facebook/react-native/pull/34936

## 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 'StringTypeAnnotation' into a single emitString function

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

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

Reviewed By: cortinico

Differential Revision: D40376836

Pulled By: cipolleschi

fbshipit-source-id: feb1b07ec7fc2c333f5054f8cd8d18457d985257
2022-10-19 01:38:28 -07:00
Antoine Doubovetzky 790f40cfeb Improve assertGenericTypeAnnotationHasExactlyOneTypeParameter tests (#34942)
Summary:
https://github.com/facebook/react-native/pull/34933 has been merged just after I pushed a new commit to the branch to improve tests of `assertGenericTypeAnnotationHasExactlyOneTypeParameter` function, but the last commit was not imported to the internal repository.

The `assertGenericTypeAnnotationHasExactlyOneTypeParameter` can throw different types of Error, and I believe that `.toThrow(Error)` is not specific enough. So I replaced it with `toThrowErrorMatchingInlineSnapshot()`.

## 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] - Improve assertGenericTypeAnnotationHasExactlyOneTypeParameter tests in parsers-commons

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

Test Plan: Some test cases were ok because the assertGenericTypeAnnotationHasExactlyOneTypeParameter function threw an Error, but for the wrong reason. I've made sure that the error displayed in the inline snapshot is the one we expect.

Reviewed By: cortinico

Differential Revision: D40384993

Pulled By: cipolleschi

fbshipit-source-id: aaa943be1e808af2c5131f7d06baf24bc3bffa31
2022-10-19 01:38:28 -07:00
dhruvtailor7 aba6be694e Extract UnsupportedObjectPropertyValueTypeAnnotationParserError to a throwing function (#34917)
Summary:
This PR is a part of https://github.com/facebook/react-native/issues/34872.
Extracted the UnsupportedObjectPropertyValueTypeAnnotationParserError in its own throwing function and reuse that function passing a proper type.

## Changelog

[Internal] [Changed] - Extract the UnsupportedObjectPropertyValueTypeAnnotationParserError in its own throwing function and reuse that function passing a proper type.

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

Test Plan:
Output of yarn jest react-native-codegen.
<img width="451" alt="Screenshot 2022-10-10 at 12 55 39 PM" src="https://user-images.githubusercontent.com/32268377/194816863-5220dbaa-3b63-42bf-8e62-9d7b915f7cbd.png">

Reviewed By: cortinico

Differential Revision: D40424885

Pulled By: cipolleschi

fbshipit-source-id: 08d4d13ee3959391261fe13c190a4bb893970757
2022-10-19 01:38:28 -07:00
Sharon Zheng 42b3ab350f fix circleci:analyze_code errors
Summary:
circleci analyze_code errors: https://app.circleci.com/pipelines/github/facebook/react-native/16638/workflows/76804803-ceb5-4fb3-bd24-26bbb9826827/jobs/321696

- __Image.flow and Image.ios:__ requires needed to be sorted alphabetically
- __error-utils-test.js:__ duplicate describe block title is used, i believe this was a typo

Changelog:
[Internal][Fixed] - fix circleci:analyze_code errors

Reviewed By: lunaleaps

Differential Revision: D40491001

fbshipit-source-id: a1df6ded77374f92e297d0a8866a2c4096e1196a
2022-10-18 18:56:19 -07:00
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
Christoph Purrer 9f465ea0ff Make react-native-codegen work on Windows within BUCK
Summary:
Changelog
[General][Internal] - Make react-native-codegen work on Windows within BUCK

This makes react-native code-gen work on Windows - by basically filling in some necessary windows commands for the existing bash/shell ones

Reviewed By: cortinico, cipolleschi

Differential Revision: D40268750

fbshipit-source-id: 0db7597999ec8108babf56abed436f6dc7789cce
2022-10-12 03:48:36 -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
Christoph Purrer 53f1f6b9cd Add TurboModule code-gen support
Summary:
Add TurboModule code-gen support for macOS and Windows

Changelog
[General][Internal] - Add TurboModule code-gen support for macOS and Windows

Reviewed By: javache

Differential Revision: D40140890

fbshipit-source-id: 60d235f16af590c07abddba3d289efa7d1d973c0
2022-10-10 15:42:06 -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