Commit Graph

1111 Commits

Author SHA1 Message Date
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
Christoph Purrer 87c356d56c Add Map / indexed object support for TypeScript parser (#35098)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/35098

Changelog:
[General][Fixed] [react-native-codegen] react-native-codegen : Add Map / indexed object support for TypeScript parser

In flow we can expose Maps via the following syntax in TM specs

`
+getMap: (arg: {[key: string]: ?number}) => {[key: string]: ?number};
`

In TypeScript writing the same spec:

`
readonly getMap: (arg: { [key: string]: number | null; }) => { [key: string]: number | null; };
`

leads to an exception the TypeScript code-gen parser

```UnsupportedObjectPropertyTypeAnnotationParserError: Module NativeTurboModuleCxx: 'ObjectTypeAnnotation' cannot contain 'TSIndexSignature'.
    at react-native-github/packages/react-native-codegen/src/parsers/typescript/modules/index.js:309:23```
```
This change fixes the TypeScript parser

Reviewed By: cipolleschi

Differential Revision: D40753368

fbshipit-source-id: 0eef8ecb63d1ed049fde1e75cc6f2ec627f1f232
2022-10-30 05:48:57 -07:00
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