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
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
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
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
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
Summary:
This diff adds type parameters to all uses of `new Array`.
Changelog: [internal]
Reviewed By: SamChou19815
Differential Revision: D41746116
fbshipit-source-id: 8aa2777dd13ef4cd9f8613adaa3509d3573d4446
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
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

Reviewed By: christophpurrer
Differential Revision: D41700084
Pulled By: rshest
fbshipit-source-id: 4bfd2d3ab3f1343bb401ba9c278dc0e0e1ea0989
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
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
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
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
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
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
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
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
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
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
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
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
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
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