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
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/34786
This diff is the TS equivalent of D39686251.
It introduces the possibility to parse a custom Native State in Typescript.
The parsing follows the exact same rules as props, as initial heuristic. This should allow enough customization for the developers who needs a custom state.
Currently, we only support using `interface` for the state and the interface must contain the `NativeState` string in its name.
This diff introduces also tests for the TypeScript parser and it aligns the tests between Flow and TS.
## Changelog
[General][Added] - Implement custom Native State parsing in TypeScript
Reviewed By: cortinico
Differential Revision: D39811476
fbshipit-source-id: 1e1b86b50b9632c13157ff6c8115f5ebcbada643
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/34753
This Diff introduce a the capability to parse custom NativeStates in Flow. To achieve this I also had to define the CodegenSchema.
The parsing follows the exact same rules as props, as initial heuristic. This should allow enough customization for the developers who needs a custom state.
There is only a case I was not able to make it work that is STATE_ALIASED_LOCALLY, from the fixtures. I don't know how diffuse it is and I think we can live with some workarounds for the time being.
This diff also adds tests for the custom Native State Flow Parser.
## Changelog
[General][Added] - Implement custom Native State parsing in Flow
Reviewed By: cortinico
Differential Revision: D39686251
fbshipit-source-id: 446997a39b33b7e9351d5ba12cecaeff33df4d16
Summary:
In `buildEventSchema` and `buildPropSchema`, they check into property types to see if the given property could be converted into an event schema or a property schema. The original implementation only handles limited cases, I refactor them and make them easier to maintain.
In `getPropertyType` in `events.js`, it handles `(T)` at a wrong place, fixed.
In `getPropertyType` in `props.js`, it doesn't handle `(T)`, fixed.
And I also fixed some other issues to make the codegen reports error better.
There are many duplicated test cases that cover every piece of the code, I changed some of them so that it tests both original cases and new cases.
## Changelog
[General] [Changed] - Handle (T) and undefined properly in turbo module component codegen
Pull Request resolved: https://github.com/facebook/react-native/pull/34693
Test Plan: `yarn jest` passed in `packages/react-native-codegen`
Reviewed By: NickGerleman
Differential Revision: D39647075
Pulled By: cipolleschi
fbshipit-source-id: 8e1df2b54aab37b7151d0bf74260e2eba0602777
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/34754
This Diff is the second step of enabling the CodeGen to parse and generate a NativeState for the components.
The feature has been largely requested by the OSS community but it could be also helpful for people in Meta.
## Changelog
[General][Added] - Always generate an empty NativeState for Fabric Components
Reviewed By: cortinico
Differential Revision: D39696435
fbshipit-source-id: e24768af78f59696c0b4db009e8065bb5c89316b
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/34750
This Diff is the first step of enabling the CodeGen to parse and generate a NativeState for the components.
The feature has been largely requested by the OSS community but it could be also helpful for people in Meta.
To allow the generation of custom `NativeState`, we first have to always generate a `ViewEventEmitter`: that's because the `ConcreteShadowNode` template lists the Generics with this order: `Name`, `Props`, `EventEmitter`, Others...
If we skip the `EventEmitters` and we put the `State`, React Native would think that the State is actually an `EventEmitter` and the build step will fail.
## Changelog
[General][Added] - Always generate a ViewEventEmitter for Fabric Components
Reviewed By: cortinico
Differential Revision: D39509869
fbshipit-source-id: 390cc146ef013baf1ed09d55a0182a5aeb5b9d9e