Commit Graph

737 Commits

Author SHA1 Message Date
Antoine Doubovetzky f16348ca03 Remove unused language argument in codegen errors (#35732)
Summary:
This is not a task from https://github.com/facebook/react-native/issues/34872 but I noticed that we were passing `language` arguments that were never used for several errors so I removed them.

## Changelog

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

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

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

[INTERNAL] [CHANGED] - Remove unused language argument in Codegen errors

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

Test Plan: I tested using Flow and Jest.

Reviewed By: christophpurrer

Differential Revision: D42266490

Pulled By: rshest

fbshipit-source-id: 7953a98586bf9e927a58222cc27cf88e9c1c1163
2022-12-28 08:46:19 -08:00
Christoph Purrer c7e1e00b82 Make C++ struct generator type-safe (#35656)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35656

Changelog: [Internal]

## Change:

https://github.com/facebook/react-native/pull/35265 added a struct generator - but it is not type safe :-(

E.g. you can write a TM Spec type as:

```
export type CustomType = {
   key: string;
   enabled: boolean;
   time?: number;
 }
```
And a C++ type as:
```
using CustomType = NativeSampleModuleBaseCustomType<float, bool, std::optional<int32_t>>;
template <>
struct Bridging<CustomType>
    : NativeSampleModuleBaseCustomTypeBridging<float, bool, std::optional<int32_t>> {};
```
and it will still compile :-( - which should not.

The reason is that the generated structs don't validate the members type :-(
```
template <typename P0, typename P1, typename P2>
struct NativeSampleModuleBaseCustomType {
  P0 key;
  P1 enabled;
  P2 time;
  bool operator==(const NativeSampleModuleBaseCustomType &other) const {
    return key == other.key && enabled == other.enabled && time == other.time;
  }
};

template <typename P0, typename P1, typename P2>
struct NativeSampleModuleBaseCustomTypeBridging {
  static NativeSampleModuleBaseCustomType<P0, P1, P2> fromJs(
      jsi::Runtime &rt,
      const jsi::Object &value,
      const std::shared_ptr<CallInvoker> &jsInvoker) {
    NativeSampleModuleBaseCustomType<P0, P1, P2> result{
      bridging::fromJs<P0>(rt, value.getProperty(rt, "key"), jsInvoker),
      bridging::fromJs<P1>(rt, value.getProperty(rt, "enabled"), jsInvoker),
      bridging::fromJs<P2>(rt, value.getProperty(rt, "time"), jsInvoker)};
    return result;
  }

  static jsi::Object toJs(
      jsi::Runtime &rt,
      const NativeSampleModuleBaseCustomType<P0, P1, P2> &value) {
    auto result = facebook::jsi::Object(rt);
    result.setProperty(rt, "key", bridging::toJs(rt, value.key));
    result.setProperty(rt, "enabled", bridging::toJs(rt, value.enabled));
    if (value.time) {
      result.setProperty(rt, "time", bridging::toJs(rt, value.time.value()));
    }
    keyToJs(rt, value.key);
    return result;
  }
};
```

This fixes that, by simply emitting conversion functions for each member such as
```
#ifdef DEBUG
  static bool keyToJs(jsi::Runtime &rt, P0 value) {
    return bridging::toJs(rt, value);
  }
  static double enabledToJs(jsi::Runtime &rt, P1 value) {
    return bridging::toJs(rt, value);
  }
  static jsi::String timeToJs(jsi::Runtime &rt, P2 value) {
    return bridging::toJs(rt, value);
  }
#endif
```

Reviewed By: cipolleschi

Differential Revision: D42082423

fbshipit-source-id: 5133f14e2aa8351e9bbbf614117a3d5894b17fa6
2022-12-16 04:26:43 -08:00
Ruslan Shestopalyuk 963e45afd1 Recursively pass invoker into ::toJS data structures for generated C++ modules
Summary:
While working on D42008409 I found out that codegen for pure C++ modules doesn't work with container types that are nested inside generated data structures, which happens because they don't have a specialization of `bridging::toJS` that wouldn't pass the `invoker` instance through.

It looks like an easiest option would be just to use `invoker` in codegen for `toJS` as well, which this diff does.

Note that I also experimented with removing `invoker` from being used in the `::toJS` specializations for containers altogether (see D42008410), as there doesn't seem to be a single use case when `invoker` would be ever needed in any `::toJS` specialization (and imagining such a scenario would be a stretch, tbh - why a conversion function would invoke anything running on JS side, given that invoker provides no return values anyway?..)

But since I am still not 100% about the invoker purpose there, I went with the codegen change.

Changelog: [Internal]

Reviewed By: christophpurrer

Differential Revision: D42008724

fbshipit-source-id: 6302d3ceacdfc8fed296ee1ef1a985f7273c2261
2022-12-13 17:07:13 -08:00
MaeIg 3f2691cf84 Extract the parseFile function in the typescript and flow parsers (#35318)
Summary:
This PR aims to extract  the parseFile function in the typescript and flow parsers.  This is to solve the problem described [here](https://github.com/facebook/react-native/pull/35158#issuecomment-1298330753) and help with the work done in 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 the parseFile function in the typescript and flow parsers

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

Test Plan:
yarn flow:
<img width="496" alt="image" src="https://user-images.githubusercontent.com/40902940/206518024-83084c3d-ab0d-4a04-810a-d40270add4b0.png">

yarn lint:
<img width="495" alt="image" src="https://user-images.githubusercontent.com/40902940/206518076-9e07eafe-db61-4c6e-8aaa-f92f190cf4f3.png">

yarn test:
<img width="389" alt="image" src="https://user-images.githubusercontent.com/40902940/206518118-5633b28c-b79b-4421-80f7-de1e03fb8ff2.png">

Reviewed By: cortinico

Differential Revision: D41248581

Pulled By: cipolleschi

fbshipit-source-id: f5b878a28a7de612fcdd1528f064b44f668503af
2022-12-13 09:00:46 -08:00
Zihan Chen (MSFT) f07490b1f1 Fix codegen output for object with indexer (#35344)
Summary:
The current implementation think `{[key:T]:U}` and `{key:object}` are the same type, which is semantically wrong.

This pull request fixes the problem and return `{type:'GenericObjectTypeAnnotation'}`, so that `{[key:T]:U}` is `Object`. The current schema cannot represent dictionary type, `Object` is the closest one.

The previous incorrect implementation actually bring in code with logic that doesn't make sense (treating indexer as property), those and related unit test are all undone.

## Changelog

[General] [Changed] - Fix codegen output for object with indexer

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

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

Reviewed By: rshest

Differential Revision: D41304475

Pulled By: cipolleschi

fbshipit-source-id: caab8e458d83f9850c5c28b67cc561a764738372
2022-12-13 03:21:02 -08:00
Christoph Purrer e327f9e20c BUCK > Enable ObjectiveC TM for MacOS (#35609)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35609

Changelog: [Internal]

Reviewed By: shwanton, cortinico

Differential Revision: D41893371

fbshipit-source-id: c60ca66d6c3957dd7850a14a1394a6b5227ff415
2022-12-12 03:23:45 -08:00
Nicola Corti 177f30a323 Bump all the @react-native/ packages to publish on main
Summary:
Nightlies are currently broken on main. That's because nightlies rely on packages that got
re-scoped under `react-native`. We need to publish them to NPM.
In order to do so, I'm bumping versions for the one that have changes on main so that they
can be published to NPM to unblock nightlies.

Changelog:
[Internal] [Changed] - Bump all the react-native/ packages to publish on main

Reviewed By: hoxyq

Differential Revision: D41840985

fbshipit-source-id: 45b691611e33668df0922d4ff753738a773f162c
2022-12-09 02:10:17 -08:00
Pieter De Baets 90538909f9 Emit name constant as part of Java codegen
Summary:
We have the expected module name available as part of the codegen schema, so we can remove the need for developers to implement the `getName` method as part of their module implementation.

Note that this method is not actually used when the TurboModules infra is used, as the moduleName from the turbo module manager is passed through to the TurboModule base class instead. Moving the method to codegen will make it easier to remove this method altogether once the old architecture is fully removed.

Changelog: [Android][Added] Support generating `getName` in react-native-codegen for Java TurboModules

Reviewed By: mdvacca

Differential Revision: D41615387

fbshipit-source-id: 6b117645fa39e5e9ab014b21198496a52f6f2ae2
2022-12-07 06:35:01 -08:00
Mike Vitousek 78b599f5b6 Add type arguments to calls to new Array() in xplat
Summary:
This diff adds type parameters to all uses of `new Array`.

Changelog: [internal]

Reviewed By: SamChou19815

Differential Revision: D41746116

fbshipit-source-id: 8aa2777dd13ef4cd9f8613adaa3509d3573d4446
2022-12-06 22:46:38 -08:00
Sam Zhou ccefad049a Enable LTI in react-native
Summary: Changelog: [Internal]

Reviewed By: panagosg7

Differential Revision: D41788271

fbshipit-source-id: 8e40dc3279ee0283b2845b9559a80862fdf59a17
2022-12-06 19:34:14 -08:00
Sam Zhou 17f221c852 Add annotations to xplat to prepare for LTI
Summary: Changelog: [Internal]

Reviewed By: mvitousek

Differential Revision: D41739285

fbshipit-source-id: 79db8afaad87a2fbba8f6d30d8468a5997c8509d
2022-12-05 14:58:24 -08:00
Nicola Corti 7933dd78da Remove .mk prebuilt file and .mk file generation from codegen (#35540)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35540

We now don't need to generate .mk files anymore, therefore I'm removing
this logic from the codegen. In RN 0.72 users should be fully migrated
to CMake.

Changelog:
[Android] [Removed] - Remove .mk prebuilt file and .mk file generation from codegen

Reviewed By: rshest

Differential Revision: D41654122

fbshipit-source-id: 3a3c01fa8ab4d48460338e1a9ce2ecbd6df25f47
2022-12-05 03:27:37 -08:00
Gabriel Donadel Dall'Agnol ea9e78d426 feat: Extract case Array and ReadOnlyArray into a single emitArrayType function (#35546)
Summary:
This PR extracts the content of the codegen case `'Array'` and `'ReadOnlyArray'` into a single `emitArrayType` 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 `emitArrayType` function.

## Changelog

[Internal] [Changed]  - Extract the content of the case 'Array' and 'ReadOnlyArray'  into a single emitArrayType function

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

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

![image](https://user-images.githubusercontent.com/11707729/205375599-3bbf02bf-85b5-41e6-ae77-fc6e12bee538.png)

Reviewed By: christophpurrer

Differential Revision: D41700084

Pulled By: rshest

fbshipit-source-id: 4bfd2d3ab3f1343bb401ba9c278dc0e0e1ea0989
2022-12-03 14:18:46 -08:00
Sam Zhou 3905fd4bd7 Annotate implicit instantiation in xplat
Summary: Changelog: [Internal]

Reviewed By: jbrown215

Differential Revision: D41662414

fbshipit-source-id: 763cde4ecc19ae2407cd9cf13557248544d2e0d1
2022-12-02 12:26:04 -08:00
MaeIg ee8701e13e Move emitUnionTypeAnnotation into parsers-primitives (#35502)
Summary:
This PR aims to move  the emitUnionTypeAnnotation function into parsers-primitives.
It was extracted to parsers-commons in a task of https://github.com/facebook/react-native/issues/34872. But, all other emit* functions are in this file, so I think it was a mistake.

## 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] - Move emitUnionTypeAnnotation function into parsers-primitives

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

Test Plan:
yarn flow:
<img width="506" alt="image" src="https://user-images.githubusercontent.com/40902940/204494702-4a190d29-38bb-4da3-beb1-236f685ce671.png">

yarn lint:
<img width="261" alt="image" src="https://user-images.githubusercontent.com/40902940/204494798-3dfb0a8a-8535-455c-9483-ec17a7d8a710.png">

yarn test:
<img width="381" alt="image" src="https://user-images.githubusercontent.com/40902940/204494766-27fdaccc-f90d-4b77-b53b-2ff0d720c74e.png">

Reviewed By: rshest

Differential Revision: D41577409

Pulled By: cortinico

fbshipit-source-id: c37b85e8a53c2b1c2bb0e00bc772dd615d1269dd
2022-12-01 09:23:45 -08:00
Rob Hogan 3e19c97646 Bump remaining build-time Babel deps
Summary:
Update `babel/*` dependencies specifying `^7.x.y` where `x > 0` to the latest available semver minor, and corresponding superficial snapshot updates reflecting a small decrease in JS bundle size.

 - `babel/core` to `^7.20.0`
 - `babel/parser` to `^7.20.0`
 - `babel/preset-env` to `^7.20.0`
 - `babel/traverse` to `^7.20.0`
 - `babel/cli` to `^7.19.0`
 - `babel/eslint-parser` to `^7.19.0`
 - `babel/preset-flow` to `^7.18.0`
 - `babel/preset-syntax-flow` to `^7.18.0`
 - Deduplicate / refresh others to take in patch updates

Changelog: [Internal] Bump Babel dependencies to latest 7.x

Reviewed By: JoeyMou

Differential Revision: D41449678

fbshipit-source-id: f04fe837a7961c4e2dde45fed59fcd138c2f8723
2022-11-30 19:16:23 -08:00
Pranav Yadav 5a20bd5b10 refactor: mv translateArrayTypeAnnotation (Flow,TS) fns > parsers-primitives.js (#35479)
Summary:
This PR is a subtask of https://github.com/facebook/react-native/issues/34872
Moved `translateArrayTypeAnnotation` (Flow,TS) fns to `parsers-primitives.js`
- combined `Flow` and `TS` `translateArrayTypeAnnotation` fn 's into common fn
- moved it to `parsers-primitives.js`
- re-organized imports and exports :)

## Changelog

[Internal] [Changed] - Moved `translateArrayTypeAnnotation` (Flow,TS) fns to `parsers-primitives.js`

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

Test Plan:
- ensure 👇 is `#00ff00`
`yarn lint && yarn flow && yarn test-ci`

Reviewed By: cipolleschi

Differential Revision: D41548046

Pulled By: GijsWeterings

fbshipit-source-id: 8fd7214f8b1e669ba42f326f814674eec179fed5
2022-11-30 04:53:34 -08:00
Zihan Chen (MSFT) 8a38e03e0f Fix codegen to add T of Promise<T> in CodegenSchema.js (#35345)
Summary:
`Promise<T>` is used very often in turbo module as function return types. So `T` is a critical thing for type safety. To enable future generator to produce more specific type for `Promise`, `T` is added to the schema.

## Changelog

[General] [Changed] - Fix codegen to add `T` of `Promise<T>` in CodegenSchema.js

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

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

Reviewed By: lunaleaps

Differential Revision: D41304647

Pulled By: cipolleschi

fbshipit-source-id: 6cdd2357b83d4d8007c881a7090cbb8969f3ae9d
2022-11-29 03:37:59 -08:00
shivenmian b7a85b59b5 chore: renamed react-native-codegen to @react-native/codegen (#34804)
Summary:
Renamed react-native-codegen package to react-native/codegen and updated references, without changing the folder name; part of RFC480 (https://github.com/facebook/react-native/issues/34692). Follow-up from https://github.com/facebook/react-native/pull/34578

## Changelog

[General] [Changed] - Renamed react-native-codegen package to react-native/codegen and updated references

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

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

Reviewed By: cortinico

Differential Revision: D39883584

Pulled By: hoxyq

fbshipit-source-id: 0ef384b75c6edd248b31e37b8f05f64b4d39ca6f
2022-11-28 08:28:51 -08:00
Vojtech Novak 90871861ce fix: codegen crash when parsing TS interfaces (#35492)
Summary:
when I'm defining a turbomodule spec, I tried to extract a common parameter into an interface.

The error I get is this:

```
[Codegen] >>>>> Processing RNSimpleToastSpec

[Codegen] Done.
/Users/vojta/_dev/_own/simple-toast/example/node_modules/react-native-codegen/lib/parsers/typescript/utils.js:111
        throw error;
        ^

TypeError: Cannot read properties of undefined (reading 'length')
    at isModuleInterface (/Users/vojta/_dev/_own/simple-toast/example/node_modules/react-native-codegen/lib/parsers/typescript/modules/index.js:695:18)
    at Array.filter (<anonymous>)
    at buildModuleSchema (/Users/vojta/_dev/_own/simple-toast/example/node_modules/react-native-codegen/lib/parsers/typescript/modules/index.js:709:44)
    at /Users/vojta/_dev/_own/simple-toast/example/node_modules/react-native-codegen/lib/parsers/typescript/index.js:158:9
    at guard (/Users/vojta/_dev/_own/simple-toast/example/node_modules/react-native-codegen/lib/parsers/typescript/utils.js:108:14)
    at buildSchema (/Users/vojta/_dev/_own/simple-toast/example/node_modules/react-native-codegen/lib/parsers/typescript/index.js:157:22)
    at Object.parseFile (/Users/vojta/_dev/_own/simple-toast/example/node_modules/react-native-codegen/lib/parsers/typescript/index.js:185:10)
```

After the fix I get this:

```
[Codegen] >>>>> Processing RNSimpleToastSpec

[Codegen] Done.
/Users/vojta/_dev/_own/simple-toast/example/node_modules/react-native-codegen/lib/parsers/typescript/utils.js:111
        throw error;
        ^

Invariant Violation: GenericTypeAnnotation 'Styles' must resolve to a TSTypeAliasDeclaration. Instead, it resolved to a 'TSInterfaceDeclaration'
```

Then I know that I should not be using an `interface` but a `type`

## Changelog

[Internal] [Fixed] - TS codegen crash when parsing interfaces

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

Test Plan:
tested locally

let me know if you want an automated test

Reviewed By: cortinico

Differential Revision: D41548015

Pulled By: cipolleschi

fbshipit-source-id: 9acf02dffbb084831690f665357fb80225cbce0d
2022-11-28 04:19:47 -08:00
Phillip Pan 6c10df5c90 update graphics imports
Summary:
i recently made a change to modularize some of our graphics dependencies

i think this codegen will be incorrect now after my diff, so i updated it so we would codegen the correct deps

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D41451842

fbshipit-source-id: 98b5576e9fbd2d693c8bcfeac39d8dfb1b1e0584
2022-11-23 01:41:23 -08:00
matiassalles99 cc311ff01a Extract the UnsupportedArrayElementTypeAnnotationParserError in its o… (#35167)
Summary:
This PR is part of https://github.com/facebook/react-native/issues/34872
This PR extracts the [UnsupportedArrayElementTypeAnnotationParserError](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/flow/modules/index.js#L132) in its own throwing function.

## Changelog
[Internal] [Changed] - Extract the UnsupportedArrayElementTypeAnnotationParserError in its own throwing function

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

Test Plan: <img width="454" alt="Screen Shot 2022-11-02 at 15 21 15" src="https://user-images.githubusercontent.com/57004457/199582495-23e4e3be-cb7e-41e8-a1fa-0250e127993c.png">

Reviewed By: cipolleschi

Differential Revision: D41437971

Pulled By: rshest

fbshipit-source-id: 14a6e09297d96f3b57568e0303e5cafff76e6f32
2022-11-22 06:16:24 -08:00
Stian Jensen 462d93d9c1 Bump jscodeshift to 0.14 (#35356)
Summary:
Jscodeshift has become maintained again in the past year, and has gotten rid of quite a good chunk of old dependencies that are no longer needed!

## 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] - update jscodeshift

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

Reviewed By: cipolleschi

Differential Revision: D41325527

Pulled By: rshest

fbshipit-source-id: 666b25c9bb3b1720479e9e098968b3b983adc2b4
2022-11-17 08:04:00 -08:00
Pranav Yadav fb37dea38e Refactor buildPropertySchema fn of (Flow, TS) into common fn (#35288)
Summary:
This PR is a task of https://github.com/facebook/react-native/issues/34872
- combined `Flow` and `TS` `buildPropertySchema` fn 's into common fn
- added callback param `resolveTypeAnnotation` to the same
- moved it to `parsers-commons.js`
- re-organized imports and exports

## Changelog

[INTERNAL] [CHANGED] - [Codegen]: Refactored `buildPropertySchema` fn of (Flow, TS) into common fn in `parsers-commons.js`

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

Test Plan:
- ensure 👇  is `#00ff00`
```bash
yarn lint && yarn flow && yarn test-ci
```

Reviewed By: christophpurrer

Differential Revision: D41247738

Pulled By: cipolleschi

fbshipit-source-id: aecc0ed8d07efa1c2c39e8a8e64b4ee73b720b8f
2022-11-16 07:45:20 -08:00
Pranav Yadav adee7be5d8 Chore: mv translateFunctionTypeAnnotation fn > parsers-commons.js (#35343)
Summary:
This PR should solve the `"Circular Dependencies"` problem/issue because of which some PRs are getting blocked as discussed here https://github.com/facebook/react-native/pull/35288#issuecomment-1314081952

- also moved below helpers to `parsers-commons.js`;
- `getTypeAnnotationParameters`
- `getFunctionNameFromParameter`
- `getParameterName`
- `getParameterTypeAnnotation`
- `getTypeAnnotationReturnType`

<3

## Changelog

[INTERNAL] [CHANGED] - Moved `translateFunctionTypeAnnotation` fn from `parsers-primitives.js` to `parsers-commons.js` also, moved it's helpers

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

Test Plan:
- ensure 👇 is `#00ff00`

`yarn lint && yarn flow && yarn test-ci`

Reviewed By: christophpurrer

Differential Revision: D41273191

Pulled By: rshest

fbshipit-source-id: cc1839a91579e7914f05516a90b280a776510c9d
2022-11-15 06:47:55 -08:00
Christoph Purrer 2eccd59d7c react-native-code-gen Add Union Type support for Java/ObjC TurboModules (#35312)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35312

Changelog:
[General][Added] react-native-code-gen Add Union Type support for Java/ObjC TurboModules

Reviewed By: javache

Differential Revision: D41216605

fbshipit-source-id: d411abed66c694d855ede40725667cbc7067538f
2022-11-14 19:11:26 -08:00
youedd a7ae9885ed move remapUnionTypeAnnotationMemberNames to Parser (#35314)
Summary:
Part of https://github.com/facebook/react-native/issues/34872#issuecomment-1304236257

> [Assigned to youedd] Create a new function [remapUnionTypeAnnotationMemberNames](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/parsers-commons.js#L110) in the [parser.js file](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/parser.js) and add documentation to it. Implement it properly in the [FlowParser.js](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/flow/parser.js#L15) and in the [TypeScriptParser.js](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/typescript/parser.js#L15). Remove the function [remapUnionTypeAnnotationMemberNames](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/parsers-commons.js#L110) and update the [emitUnionTypeAnnotation](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/parsers-commons.js#L110) signature to accept a Parser parameter instead of a language one. Use the new Parser function instead of the old one [here](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/parsers-commons.js#L139).

## 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] - move remapUnionTypeAnnotationMemberNames to the parsers implementations

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

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

![image](https://user-images.githubusercontent.com/19575877/201389910-31d48601-7023-4c94-a6d5-efccb18629cd.png)

Reviewed By: christophpurrer

Differential Revision: D41247716

Pulled By: cipolleschi

fbshipit-source-id: 6f708895392d5bdac5d4edbc67587194321ddb3d
2022-11-14 12:28:35 -08:00
Pieter Vanderwerff f45329221a Fix and enforce empty array providers in xplat/js
Reviewed By: bradzacher

Differential Revision: D41207298

fbshipit-source-id: cd25a3edbb8bb94fd18434c9cee16f9c36f9b74a
2022-11-14 10:41:58 -08:00
Zihan Chen (MSFT) ae1d54bc5a Add TSMethodSignature to react-native-codegen (#35311)
Summary:
Refering to "Support function signature along with function type properties in commands" in https://github.com/facebook/react-native/issues/34872

Many TypeScript programmers prefer `{ name(arg:string):void; }` to `{ readonly name:(arg:string)=>void; }`.

In this pull request, I updated test cases in both commands and modules to cover it, with missing implementation.

Command arguments are `NamedShape<T>` but the `optional` field is missing, it is also fixed.

## Changelog

[General] [Changed] - Add `TSMethodSignature` to react-native-codegen

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

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

Reviewed By: rshest

Differential Revision: D41217482

Pulled By: cipolleschi

fbshipit-source-id: 480af118d09b022bae919c5391547fd82c1a7cc9
2022-11-14 08:01:20 -08:00
Mike Vitousek ed02d4baf0 Annotate implicit instantiations in xplat, defaulting to any
Summary:
Add explicit annotations to underconstrained implicit instantiations as required for Flow's Local Type Inference project. This codemod prepares the codebase to match Flow's new typechecking algorithm. The new algorithm will make Flow more reliable and predictable.

This diff adds `any` or `$FlowFixMe` in cases where more precise types could not be determined.

Details:
- Codemod script: `.facebook/flowd codemod annotate-implicit-instantiations ../../xplat/js --default-any --write`
- Local Type Inference announcement: [post](https://fb.workplace.com/groups/flowlang/posts/788206301785035)
- Support group: [Flow Support](https://fb.workplace.com/groups/flow)

drop-conflicts
bypass-lint

Reviewed By: SamChou19815

Differential Revision: D41226960

fbshipit-source-id: e5e3edbb1aed849f90cc683a4d416a9a2f8f3a19
2022-11-11 12:54:51 -08:00
Zihan Chen (MSFT) 813fd04118 Add intersection types in react-native-codegen for TypeScript (#35247)
Summary:
Refer to "Support intersection of object types, `{...a, ...b, ...}` in Flow is equivalent to `a & b & {...}` in TypeScript, the order and the form is not important." in https://github.com/facebook/react-native/issues/34872

In this change I also extract the common part from `getTypeAnnotation` and `getTypeAnnotationForArray` into `getCommonTypeAnnotation`. Most of the differences are about `default` in the schema. After a schema is generated from `getCommonTypeAnnotation` successfully, `getTypeAnnotation` will fill `default` if necessary, while `getTypeAnnotationForArray` does nothing.

## Changelog

[General] [Changed] - Add intersection types in react-native-codegen for TypeScript

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

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

Reviewed By: cipolleschi

Differential Revision: D41105744

Pulled By: lunaleaps

fbshipit-source-id: cd250a9594a54596a20ae26e57a1c801e2047703
2022-11-10 15:28:17 -08:00
Antoine Doubovetzky edc4ea0a67 Use parser instead of language in MissingTypeParameterGenericParserError and MoreThanOneTypeParameterGenericParserError (#35294)
Summary:
Part of https://github.com/facebook/react-native/issues/34872:
> Update the [IncorrectlyParameterizedGenericParserError](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/errors.js#L134) error in the error.js file to accept a Parser instead of a ParserType parameter. Use the nameForGenericTypeAnnotation method of the parser to extract the genericName and delete the ternary operator.

Since the task was added to the issue we split the IncorrectlyParameterizedGenericParserError into 2 errors: MissingTypeParameterGenericParserError and MissingTypeParameterGenericParserError (https://github.com/facebook/react-native/pull/35134/), so I applied the change on both errors.

## 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] - Use parser instead of language in MissingTypeParameterGenericParserError and MoreThanOneTypeParameterGenericParserError

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

Test Plan: I tested using Flow and Jest commands. More specifically, the tests that cover this change are the ones I renamed.

Reviewed By: christophpurrer

Differential Revision: D41181069

Pulled By: cipolleschi

fbshipit-source-id: 3412e29b1319a28b3ec6afb38b1eda448055fa6a
2022-11-10 10:12:15 -08:00
Gabriel Donadel Dall'Agnol f849f49525 chore: Add getKeyName function to codegen Parser class (#35202)
Summary:
This PR adds a  `getKeyName`  function to the codegen Parser class and implements it in the Flow and TypeScript parsers as requested on https://github.com/facebook/react-native/issues/34872.

## Changelog

[Internal] [Added] - Add `getKeyName` function to codegen Parser class

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

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

![image](https://user-images.githubusercontent.com/11707729/200028600-87e9c1d7-d56d-4cf7-bdbc-18bdf1b03fc5.png)

Reviewed By: cipolleschi

Differential Revision: D41081711

Pulled By: jacdebug

fbshipit-source-id: 7ad2953a0e2f90f04d03270bda40d669d4d0d50a
2022-11-10 09:04:48 -08:00
Tarun Chauhan e97fb466a0 implement checkIfInvalidModule in parsers (#35261)
Summary:
Part of the Codegen umbrella Issue https://github.com/facebook/react-native/issues/34872

> Create a checkIfInvalidModule function in the [parser.js file](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/parser.js) and document it. Implement [this logic](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/error-utils.js#L127-L132) in the [FlowParser.js](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/flow/parser.js#L15) and [this logic](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/error-utils.js#L136-L141) in the [TypeScriptParser.js](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/typescript/parser.js#L15). Refactor the [throwIfIncorrectModuleRegistryCallTypeParameterParserError function](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/error-utils.js#L109) to accept a Parser instead of a ParserType and use the newly created function instead of the if (language) logic.

## Changelog

[Internal] [Added] - Add checkIfInvalidModule in the Parser interface and implement it in both parsers. Refactor [throwIfIncorrectModuleRegistryCallTypeParameterParserError](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/error-utils.js#L109) to use this new function.

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

Test Plan:
Run yarn jest react-native-codegen
<img width="788" alt="image" src="https://user-images.githubusercontent.com/34857453/200616752-155d638c-5ef4-4d8b-be79-07a128523910.png">

Reviewed By: christophpurrer

Differential Revision: D41125704

Pulled By: cipolleschi

fbshipit-source-id: 029d5511050dbe975a38a890d0238cb6f3b542ea
2022-11-10 07:56:07 -08:00
Christoph Purrer c0a06d2e6f react-native code-gen > C++ TurboModules struct support (#35265)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35265

This adds a templating layer for C++ TurboModules to automatically generate struct templates from TurboModule specs.

You have to define concrete types for those templates to use them in your C++ TurboModule.

E.g. for the JS flow type:
```
export type ObjectStruct = {|
  a: number,
  b: string,
  c?: ?string,
|};
```
code-gen will now generate the following template code:
```
#pragma mark - NativeCxxModuleExampleCxxBaseObjectStruct

template <typename P0, typename P1, typename P2>
struct NativeCxxModuleExampleCxxBaseObjectStruct {
  P0 a;
  P1 b;
  P2 c;
  bool operator==(const NativeCxxModuleExampleCxxBaseObjectStruct &other) const {
    return a == other.a && b == other.b && c == other.c;
  }
};

template <typename P0, typename P1, typename P2>
struct NativeCxxModuleExampleCxxBaseObjectStructBridging {
  static NativeCxxModuleExampleCxxBaseObjectStruct<P0, P1, P2> fromJs(
      jsi::Runtime &rt,
      const jsi::Object &value,
      const std::shared_ptr<CallInvoker> &jsInvoker) {
    NativeCxxModuleExampleCxxBaseObjectStruct<P0, P1, P2> result{
      bridging::fromJs<P0>(rt, value.getProperty(rt, "a"), jsInvoker),
      bridging::fromJs<P1>(rt, value.getProperty(rt, "b"), jsInvoker),
      bridging::fromJs<P2>(rt, value.getProperty(rt, "c"), jsInvoker)};
    return result;
  }

  static jsi::Object toJs(
      jsi::Runtime &rt,
      const NativeCxxModuleExampleCxxBaseObjectStruct<P0, P1, P2> &value) {
    auto result = facebook::jsi::Object(rt);
    result.setProperty(rt, "a", bridging::toJs(rt, value.a));
    result.setProperty(rt, "b", bridging::toJs(rt, value.b));
    if (value.c) {
      result.setProperty(rt, "c", bridging::toJs(rt, value.c.value()));
    }
    return result;
  }
};
```
and you can use it in our C++ TurboModule for example as:
```
using ObjectStruct = NativeCxxModuleExampleCxxBaseObjectStruct<
    int32_t,
    std::string,
    std::optional<std::string>>;

template <>
struct Bridging<ObjectStruct>
    : NativeCxxModuleExampleCxxBaseObjectStructBridging<
          int32_t,
          std::string,
          std::optional<std::string>> {};
```
or as
```
using ObjectStruct = NativeCxxModuleExampleCxxBaseObjectStruct<
    float,
    folly::StringPiece,
    std::optional<std::string>>;

template <>
struct Bridging<ObjectStruct>
    : NativeCxxModuleExampleCxxBaseObjectStructBridging<
          float,
          folly::StringPiece,
          std::optional<std::string>> {};
```
Or as
...

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D41133761

fbshipit-source-id: fdf36e51073cb46c5234f6121842c79a884899c7
2022-11-09 13:23:05 -08:00
Marco Fiorito 64ea7ce6c5 Chore: move translateFunctionTypeAnnotation into emitFunction (#35287)
Summary:
Part of https://github.com/facebook/react-native/issues/34872

In this PR was moved the translateFunctionTypeAnnotation invocation ([Flow](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/flow/modules/index.js#L362), [TypeScript](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L376)) into the emitFunction call so that the case FuntionTypeAnnotation results in a one-liner

## Changelog

[Internal] [Changed] - Move the translateFunctionTypeAnnotation invocation into the emitFunction

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

Test Plan: <img width="266" alt="image" src="https://user-images.githubusercontent.com/18408823/200852605-96c233d9-b524-4b7c-bc41-5543534c296b.png">

Reviewed By: christophpurrer

Differential Revision: D41157574

Pulled By: rshest

fbshipit-source-id: 21f6fe7dcffd30f4009ca91a6dec81bbd4b0902a
2022-11-09 12:18:31 -08:00
Pranav Yadav 5744b219c7 Extract tryParse (Flow, TypeScript) lambda into parseObjectProperty fn (#35076)
Summary:
This PR is a task of https://github.com/facebook/react-native/issues/34872

> Extract the content of the tryParse (Flow, TypeScript)lambda into a proper `parseObjectProperty` function into the parsers-commons.js file.
also,
- added new helper fn `isObjectProperty` in `parsers-commons.js` file.
- added tests for `isObjectProperty` and `parseObjectProperty` fn 's

## Changelog

[Internal] [Changed] - Extracted the content of the `tryParse` ([Flow](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/flow/modules/index.js#L292-L337), [TypeScript](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L306-L351)) lambda into a proper `parseObjectProperty` fn into the `parsers-commons.js` file.

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

Test Plan:
- run
```bash
yarn lint && yarn flow && yarn test-ci
```
- and ensure everything is �

<img width="720" alt="image" src="https://user-images.githubusercontent.com/55224033/200105151-360b9b5e-52c7-4586-89b0-6860e9725f6e.png">

Reviewed By: cortinico

Differential Revision: D40797241

Pulled By: cipolleschi

fbshipit-source-id: 48b8900ead70d5eda2496f9ce044c11a9599a177
2022-11-09 02:11:17 -08:00
Antoine Doubovetzky 8a847a30e1 Replace ternary in assertGenericTypeAnnotationHasExactlyOneTypeParameter with typeParameterInstantiation attribute in parser (#35157)
Summary:
Part of https://github.com/facebook/react-native/issues/34872:
> Create a new function typeParameterInstantiation in the [parsers.js file](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/parser.js) and add documentation to it. Implement it properly in the [FlowParser.js](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/flow/parser.js#L15) and in the [TypeScriptParser.js](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/typescript/parser.js#L15). Update the signature of [assertGenericTypeAnnotationHasExactlyOneTypeParameter](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/parsers-commons.js#L67) function to take the Parser instead of the language and use the new function in place of the [ternary operator ?:](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/parsers-commons.js#L83).

There are 3 things I'm not sure about:
1. The issue suggests to create a new function. For this case I believe an attribute is simpler. Is there a reason to prefer a function ?
2. To update the tests I had to create a mocked parser. I created a new file `parserMock` (I took example on [AnimatedMock](https://github.com/facebook/react-native/blob/main/Libraries/Animated/AnimatedMock.js)). Does it seem ok ?
3. I'm not sure what to add in the documentation of `typeParameterInstantiation`

## 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] - Replace ternary in assertGenericTypeAnnotationHasExactlyOneTypeParameter with typeParameterInstantiation attribute in parser

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

Test Plan: I tested using Jest and Flow commands.

Reviewed By: rshest

Differential Revision: D40889856

Pulled By: cipolleschi

fbshipit-source-id: 8d9a8e087852f98dcc3fc0ecf1d4a7153f482ce7
2022-11-08 11:55:23 -08:00
Dmitry Rykun d62b0b463b Bump dependency versions to 0.72.0 after the branch cut
Summary:
Changelog
[General][Changed] - Bump dependency versions to 0.72.0 after the branch cut.

Reviewed By: cipolleschi

Differential Revision: D41079762

fbshipit-source-id: 83e912c4eaf969c1673ccc5fa854646efa99fa4a
2022-11-07 06:57:35 -08:00
Gabriel Donadel Dall'Agnol 62244d4a1e chore: Extract codegen translateFunctionTypeAnnotation into a common function (#35182)
Summary:
This PR extracts the codegen `translateFunctionTypeAnnotation` Flow and TypeScript functions into a single common function in the `parsers-primitives.js` file that can be used by both parsers as requested on https://github.com/facebook/react-native/issues/34872.

## Changelog

[Internal] [Changed] -  Extract codegen `translateFunctionTypeAnnotation` into a common function in the` parsers-primitives.js` file

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

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

![image](https://user-images.githubusercontent.com/11707729/199625849-e89b647f-63fb-40f8-b643-a59dedb4c59a.png)

Reviewed By: cortinico

Differential Revision: D41030544

Pulled By: rshest

fbshipit-source-id: bc93c21e31ed4e8c3293cafe3d808d9f36cf8ecc
2022-11-07 06:14:38 -08:00
Pieter De Baets 6db3995175 Improve @Nullable annotions in Java TurboModule codegen
Summary:
Noticed these types could be improved based on the tests added in D40979066 (https://github.com/facebook/react-native/commit/e81c98c842380d8b72c1dc8d4a6e64f760e2a58c).

Changelog: [Android][Fixed] Corrected Nullable annotations for parameters and return values in TurboModules codegen

Reviewed By: mdvacca, cipolleschi

Differential Revision: D40979940

fbshipit-source-id: cfc352a9e7eb9f59e2cce3d7da110a9a8d32db4b
2022-11-07 05:13:30 -08:00
Ruslan Lesiutin d03a29ce5f refactor(react-native-github): move ImagePickerIOS to internal (#35199)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35199

**Changelog:**
[iOS][Removed] - Removed ImagePickerIOS module native sources
[JS][Removed] - Removed ImagePickerIOS module from react-native

Reviewed By: cortinico

Differential Revision: D40859520

fbshipit-source-id: a6a114a05574d46ea62600999bff95025ba7cdc8
2022-11-04 08:08:54 -07:00
Pranav Yadav 95e685a44d mv emitMixedTypeAnnotation fn > parsers-primitives.js (#35185)
Summary:
This PR is a task of https://github.com/facebook/react-native/issues/34872

- Moved the [emitMixedTypeAnnotation](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/parsers-commons.js#L102) function to the [`parser-primitives.js` file](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/parsers-primitives.js).
- Moved tests for the same respectively
- Fixed/Updated imports and exports for the same respectively

## 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] - Moved the `emitMixedTypeAnnotation` function to the `parser-primitives.js` file.

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

Test Plan:
`yarn test-ci`
![image](https://user-images.githubusercontent.com/55224033/199693475-60c034bf-cd5c-4cb8-bfe8-e7c7ccbc4300.png)

Reviewed By: cipolleschi

Differential Revision: D40993027

Pulled By: rshest

fbshipit-source-id: 5e025804f4ef6723396accf2f859483f76cb6cd6
2022-11-04 05:11:39 -07:00
Dmitry Rykun 8183aac0b1 Bump dependency versions before the branch cut 0.71.0
Summary: Changelog: [General][Changed] - Bump dependency versions.

Reviewed By: cipolleschi

Differential Revision: D40991336

fbshipit-source-id: 71c8edbeb274d095403b2f17e60f217d16fe01c0
2022-11-03 17:28:26 -07:00
Pieter De Baets e81c98c842 Fix Cpp codegen handling of optional arguments
Summary:
Changelog:
[General][Fixed] - Codegen for C++ TurboModules of optional method arguments was incorrect

Reviewed By: christophpurrer

Differential Revision: D40979066

fbshipit-source-id: 5bb48dbafc14dcea21b7e0b15e3f4bb527bc8476
2022-11-03 11:20:16 -07:00
Mike Vitousek 91d58cf5b5 Codemod cycle annotations for xplat/js
Summary:
Add annotations using flow codemod annotate-cycles --write

Changelog: [internal]

Reviewed By: SamChou19815

Differential Revision: D40896688

fbshipit-source-id: 0c32932d17542be070360db29b7797f8e6e5978b
2022-11-01 17:13:27 -07:00
Antoine Doubovetzky 83e2126b57 Extract isModuleRegistryCall function in parsers/utils (#35139)
Summary:
This PR is a task from https://github.com/facebook/react-native/issues/34872:
> Extract the function isModuleRegistryCall ([Flow](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/flow/utils.js#L175-L211) [TypeScript](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/typescript/utils.js#L167-L203)) 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 isModuleRegistryCall in parsers/utils

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

Test Plan: I tested using Jest and Flow commands.

Reviewed By: rshest

Differential Revision: D40850471

Pulled By: cipolleschi

fbshipit-source-id: 34ec8ea4d7175e205315d60f200df093f1204b7b
2022-10-31 13:56:27 -07:00
Antoine Doubovetzky 56d7a87e84 Fix assertGenericTypeAnnotationHasExactlyOneTypeParameter throwing wrong error (#35134)
Summary:
1. I noticed there was a mistake in the [IncorrectlyParameterizedGenericParserError](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/errors.js#L159):
```
if (
  genericTypeAnnotation.typeParameters.type ===
    'TypeParameterInstantiation' &&
  genericTypeAnnotation.typeParameters.params.length !== 1
) {
```

Here we should replace ` 'TypeParameterInstantiation'` with ` 'TSTypeParameterInstantiation'` when the language is `TypeScript`.

The result is that we get a ["Couldn't create IncorrectlyParameterizedGenericParserError"](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/errors.js#L172) error instead of ["Module testModuleName: Generic 'typeAnnotationName' must have exactly one type parameter."](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/parsers-commons.js#L88).

I added a [test case](https://github.com/facebook/react-native/commit/2f161166c033cc9de67e04cd683554b05c6173f8) to cover this case:
<img width="1008" alt="Capture d’écran 2022-10-30 à 13 55 56" src="https://user-images.githubusercontent.com/17070498/198879598-ab5a6092-8cbf-422a-9993-2f3f92c9d84c.png">

2. Looking closely at where IncorrectlyParameterizedGenericParserError is used, I noticed that the logic was duplicated in [assertGenericTypeAnnotationHasExactlyOneTypeParameter](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/parsers-commons.js#L65).

I believe that the logic should reside in `assertGenericTypeAnnotationHasExactlyOneTypeParameter` so I split the `IncorrectlyParameterizedGenericParserError` in 2 different errors.

## 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] - Fix assertGenericTypeAnnotationHasExactlyOneTypeParameter throwing wrong error

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

Test Plan: I tested using Jest and Flow commands.

Reviewed By: rshest

Differential Revision: D40853200

Pulled By: cipolleschi

fbshipit-source-id: 7040e57e0a2f511ba23fd4c54beae2ccff2fa89d
2022-10-31 13:56:27 -07:00
Gabriel Donadel Dall'Agnol ea55e3bf8d chore: Unify codegen Flow and TS default case from translateTypeAnnotation (#35086)
Summary:
This PR unifies the Flow and TS `default:` case from codegen `translateTypeAnnotation` function into a single function
called `translateDefault` inside `parser-commons.js` as requested on https://github.com/facebook/react-native/issues/34872.

## Changelog

[Internal] [Changed] - Unify codegen Flow and TS default case from translateTypeAnnotation

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

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

![image](https://user-images.githubusercontent.com/11707729/197931439-a0f0f7cd-eee7-4908-a7f1-856b40954178.png)

Reviewed By: cortinico

Differential Revision: D40801612

Pulled By: cipolleschi

fbshipit-source-id: 612768d6fabe091ac428e7d8416c6da059fe1332
2022-10-31 13:56:27 -07:00
Riccardo Cipolleschi a2166b24f8 bump codegen to v0.71.1 (#35154)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35154

This diff bumps the codegen to v0.71.1, preparing it for the branch cut.

## Changelog
[General][Changed] - Bump codegen version

Reviewed By: dmytrorykun

Differential Revision: D40852498

fbshipit-source-id: ba1dc87f3726bc27cbd176f160c62a0bdc291433
2022-10-31 12:31:00 -07:00