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
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
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
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
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
Summary:
This PR is part of https://github.com/facebook/react-native/issues/34872.
As a part of this PR, `UntypedModuleRegistryCallParserError` is separated into its own throwing function in `error-utils.js` file and is used in both Flow and TypeScript parsers
## Changelog
[Internal] [Changed] - Extract `UntypedModuleRegistryCallParserError` to a separate function inside `error-utils.js` file.
Pull Request resolved: https://github.com/facebook/react-native/pull/34953
Test Plan:
Added unit case in error-utils-test.js file to test the new function.
Output of `yarn jest react-native-codegen` ensures all passed test cases.
<img width="450" alt="Screenshot 2022-10-12 at 12 44 36 PM" src="https://user-images.githubusercontent.com/32268377/195277708-97340db3-f3d8-48a3-9a59-95d2747c67b0.png">
Reviewed By: christophpurrer
Differential Revision: D40297017
Pulled By: cipolleschi
fbshipit-source-id: b02dcf0e110ab903a0d1831783194ae4a543075b
Summary:
This PR is part of https://github.com/facebook/react-native/issues/34872.
This PR extracts `IncorrectModuleRegistryCallTypeParameterParserError` exception to a separate function inside an `error-utils.js` file
## Changelog
[Internal] [Changed] - Extract `IncorrectModuleRegistryCallTypeParameterParserError` to a seperate function inside `error-utils.js`
Pull Request resolved: https://github.com/facebook/react-native/pull/34941
Test Plan:
```sh
yarn jest react-native-codegen
```
Added unit case in `error-utils-test.js` file
<img width="940" alt="Screenshot 2022-10-11 at 4 42 03 PM" src="https://user-images.githubusercontent.com/86605635/195076564-3b023c17-661c-4330-805c-0216c4391d59.png">
Reviewed By: dmytrorykun
Differential Revision: D40296642
Pulled By: cipolleschi
fbshipit-source-id: 7c7bba6a4f68e9b8fa4729a7651f22cce6d7ca6e
Summary:
This PR is part of https://github.com/facebook/react-native/issues/34872
This PR extracts `IncorrectModuleRegistryCallArityParserError` exception to `throwIfIncorrectModuleRegistryCallArityParserError` inside an `error-utils.js` file.
## Changelog
[Internal] [Changed] - Extracted IncorrectModuleRegistryCallArityParserError exception to throwIfIncorrectModuleRegistryCallArityParserError function
Pull Request resolved: https://github.com/facebook/react-native/pull/34940
Test Plan:
Added unit case in error-utils-test.js file
yarn jest react-native-codegen
<img width="1144" alt="Screenshot 2022-10-11 at 4 04 55 PM" src="https://user-images.githubusercontent.com/22423684/195070498-627d1bb8-53b1-43d3-b410-462e4f0da23a.png">
Reviewed By: dmytrorykun
Differential Revision: D40296626
Pulled By: cipolleschi
fbshipit-source-id: 33a299b1adf6334753c2390a81a54832c9096ec5
Summary:
This PR extracts the codegen `ModuleInterfaceNotFoundParserError` exception into a separate function inside `error-utils.js` so that it can be used by both Flow and Typescript parsers as requested on https://github.com/facebook/react-native/issues/34872. This also adds unit tests to the new `throwIfModuleInterfaceNotFound` function.
## Changelog
[Internal] [Changed] - Extract codegen `ModuleInterfaceNotFoundParserError` in a separate function that can de used by Flow and TypeScript parsers
Pull Request resolved: https://github.com/facebook/react-native/pull/34922
Test Plan:
Run `yarn jest react-native-codegen` and ensure CI is green

Reviewed By: dmytrorykun
Differential Revision: D40296533
Pulled By: cipolleschi
fbshipit-source-id: 205469b15337f6c3847936a6ef5427b5a9e08665
Summary:
Changelog
[General][Internal] - Make react-native-codegen work on Windows within BUCK
This makes react-native code-gen work on Windows - by basically filling in some necessary windows commands for the existing bash/shell ones
Reviewed By: cortinico, cipolleschi
Differential Revision: D40268750
fbshipit-source-id: 0db7597999ec8108babf56abed436f6dc7789cce
Summary:
This PR extracts the content of the codegen case `'Stringish'` into a single `emitStringish` function inside the `parsers-primitives.js` file and uses it in both Flow and TypeScript parsers as requested on https://github.com/facebook/react-native/issues/34872. This also adds unit tests to the new `emitStringish` function.
## Changelog
[Internal] [Changed] - Extract the content of the case 'Stringish' into a single emitStringish function
Pull Request resolved: https://github.com/facebook/react-native/pull/34936
Test Plan:
Run `yarn jest react-native-codegen` and ensure CI is green

Reviewed By: cipolleschi
Differential Revision: D40255921
Pulled By: rshest
fbshipit-source-id: 9c08f81f12c93995bb6ba032fabcd6451b8dc7c1
Summary:
Add TurboModule code-gen support for macOS and Windows
Changelog
[General][Internal] - Add TurboModule code-gen support for macOS and Windows
Reviewed By: javache
Differential Revision: D40140890
fbshipit-source-id: 60d235f16af590c07abddba3d289efa7d1d973c0
Summary:
This PR reduces code duplication by extracting all the errors in the module/errors into a single parsers/errors.js file. All the errors must drop the corresponding Flow or Typescript token in the name and take an extra language parameter in the constructor. Also, rename the hasteModuleName parameter to nativeModuleName.
Part of https://github.com/facebook/react-native/issues/34872
## Changelog
<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[Internal] [Changed] - Extract all the parsers errors in the module/errors into a single parsers/errors.js file
Pull Request resolved: https://github.com/facebook/react-native/pull/34896
Test Plan:
run ```yarn jest react-native-codegen``` and check all test case passes.
<img width="793" alt="image" src="https://user-images.githubusercontent.com/34857453/194545577-cf2d980b-b6b7-4f93-b13e-2e45d92dceab.png">
Reviewed By: rshest
Differential Revision: D40176486
Pulled By: rshest
fbshipit-source-id: b33ae49b2bcceeffd307370ee5e3b24a9e1bb340
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/34910
This Diff adds supports on the CustomState generation for ImageSource and ImageRequests, to enable NativeComponents to use the ImageSource loading provided by React Native.
To achieve this, I also had to fox some errors in the imports and to introduce some functions to decorate parameters.
This diff also introduces the tests for thise additional types in both generators and parsers.
## Changelog
[General][Added] - add support for ImageSource and ImageRequest in the State.
Reviewed By: cortinico
Differential Revision: D39884889
fbshipit-source-id: ae3d2d51dfe6a4fe688dc78fec83f428beb8d443
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/34796
This diff introduces the generation of custom native states using basic types as we do with the Props.
To make it work, the custom types are already writte in the Props.h file, therefore the State.h file must import that other file to have access to the required types.
This diff adds and updates the tests for the State.
## Changelog
[General][Added] - Generate custom Native State
Reviewed By: cortinico
Differential Revision: D39816763
fbshipit-source-id: 42d1aa9a6df23145f4a46ae8ccfb43d81fa651fb
Summary:
This PR is a task from https://github.com/facebook/react-native/issues/34872
_Extract the modules/utils.js from the flow and typescript folders in a shared parsers-commons.js file. Then, have the two parsers use the same wrapModuleSchema function for modules._
(`wrapModuleSchema` is a copy-paste mistake, in this case it is `wrapNullable` and `unwrapNullable`)
## Changelog
<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[Internal] [Changed] - Extracts Codegen's modules/utils.js files from the flow and typescript folders in parsers-commons
Pull Request resolved: https://github.com/facebook/react-native/pull/34898
Test Plan:
I ran `yarn jest react-native-codegen`:
<img width="775" alt="Capture d’écran 2022-10-07 à 21 29 48" src="https://user-images.githubusercontent.com/17070498/194639515-a446c2cf-daf3-43a1-9833-cd546ca5865e.png">
Reviewed By: cipolleschi
Differential Revision: D40193740
Pulled By: cipolleschi
fbshipit-source-id: 02cbacc215fe5dd9bdd0839d8796587ab2821906
Summary:
A few fixings to make `yarn jest react-native-doegen` works on Windows:
- ~~Add a `.gitignore` file to tell git not to track generated/temporary files.~~
- There is no `rm` on Windows, change it to `rimraf`.
I have been using it in the last 3 months and it works perfectly on Windows, otherwise I could not even build the code in my laptop.
## Changelog
[General] [Changed] - Make `yarn` and `yarn jest react-native-codegen` works on Windows with git
Pull Request resolved: https://github.com/facebook/react-native/pull/34854
Test Plan: `yarn jest react-native-codegen` passed
Reviewed By: cortinico
Differential Revision: D40059524
Pulled By: cortinico
fbshipit-source-id: e3cde2506c7d18c2b580099257637b90f4cb328c
Summary:
This diff helps the library maintainer to keep their spec file platform specific if some specs make no sense in one platform or in the other.
We are filtering the spec files when we need to create the Schema.
The diff modifies also the call sites in the `scripts` (for iOS) and in the `gradle-plugin` (for Android).
It also adds tests for the new functions in the CLI.
The change is completely additive and it should not change any pre-existing behaviour.
## Changelog
[General][Added] - Add support for platform-specific specs
Reviewed By: cortinico
Differential Revision: D40008581
fbshipit-source-id: b7fcf6d38f85fe10e4e00002d3c6f2910abdbe35
Summary:
`TSParenthesizedType`, `TSUnionType`, `TSNullKeyword`, `TSUndefinedKeyword`, `TSVoidKeyword` etc are repeatly processed in so many places. In this change I put them in a new file `parseTopLevelType.js`, and everyone call that file, all repeat implementation are deleted.
The `parseTopLevelType` function will look into a type consisted by the above types in any possible combination (but still very easy to do), and tell you if a type is nullable, or if there is a default value, and what is the real type with all noises removed.
Array types and union types are processed in component twice, for property of array, and property of nested arrays (`componentsUtils.js`). They are extracted into single functions.
## Changelog
[General] [Changed] - Refactor in turbo module TypeScript codegen: process `(T)`, `T|U`, `T|undefined` and related stuff in a central place
Pull Request resolved: https://github.com/facebook/react-native/pull/34814
Test Plan: `yarn jest react-native-codegen` passed
Reviewed By: yungsters, sammy-SC
Differential Revision: D40094373
fbshipit-source-id: f28e145bc4e7734be9036815ea425d820eadb8f0
Summary:
This change will expose the rrc_image module to be consumed via Prefab by user projects. This is needed as part of a change of the codegen to support custom states.
Changelog:
[Internal] [Changed] - Expose rrc_image to consuming build
Reviewed By: cipolleschi
Differential Revision: D40098541
fbshipit-source-id: 2e07d8b19f53ba93920009603c95a43b01f131eb
Summary:
This change will expose the `react_render_imagemanager` module to be consumed via Prefab by user projects. This is needed as part of a change of the codegen to support custom states.
Changelog:
[Internal] [Changed] - Expose react_render_imagemanager to consuming build
Reviewed By: cipolleschi
Differential Revision: D40022929
fbshipit-source-id: ece47503b11a641067ae6db82f1d69b244c9c5be
Summary:
Currently, it is not clear how to run codegen tests in the OSS.
## Changelog
[General][Added] - Add instructions about how to add tests in the OSS
Reviewed By: cortinico
Differential Revision: D40020907
fbshipit-source-id: 073ec8bf08d2a9e8b26287763dd881371ecf561d
Summary:
When using flow syntax like this, the parser would throw an error.
```
const foo = new ClassInstance();
export type {foo};
```
Changelog: [Internal]
Reviewed By: christophpurrer
Differential Revision: D39850098
fbshipit-source-id: 28a7748892559c2c4a0fb8afa8612cbeb5568058
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/34800
The TypeScript parser was not handling negative default values properly. The reason why is because the AST for those values is structurally different and wraps them in a `UnaryExpression` with the `-` operator.
This Diff adds the support for those default values and it also add some tests in both Flow and TS.
## Changelog
[General][Fixed] - Properly parse negative values
Reviewed By: cortinico
Differential Revision: D39847784
fbshipit-source-id: 95fc5768987477c540a54a7c4e4ff785d7a1e5d7
Summary:
Interface was supported in component, but it only allows interfaces in limited cases.
In this change, I extended interface support to all places where object literal type is supported.
I also refactor the code so that properties and events are able to share the same implementation.
In order not to mess up the diff, I noticed that implementations are repeated in processing array properties and non-array properties. But I leave it without refactoring. I will do it in future PRs.
I also commented potential problems I found in the code.
## Changelog
[General] [Changed] - Fix interface support in turbo module TypeScript codegen (component only)
Pull Request resolved: https://github.com/facebook/react-native/pull/34778
Test Plan: `yarn jest react-native-codegen` passed
Reviewed By: cortinico
Differential Revision: D39809230
Pulled By: cipolleschi
fbshipit-source-id: cfb51ce915249b5abceafee1c08b7e5762d03519