-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Codegen 78 & 79]: Merge TS & Flow parsers' logic for Partial
case to emitPartial
fn & commonTypes
cases into emitCommonTypes
fn
#36450
Conversation
Base commit: 93c1fbd |
Edit: forgot to mention u @cipolleschi I tried to look |
Partial
case to emitPatial
fn & commonTypes
cases into emitCommonTypes
fnPartial
case to emitPartial
fn & commonTypes
cases into emitCommonTypes
fn
f9ce471
to
7ce1db6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this job. I left a few comment to simplify even further the codebase.
I tried to have a look at the error, but I couldn't figure out what's going wrong.
The problem is not in the NativeModules specifically, it looks like that it can't find the right type when going over the switch... i.e. the commonType
variable result null
and it throws an error.
I think that the best way to figure out what's going on here is to debug. To do so:
- Pick a failing test. For example: RN Codegen TypeScript Parser › can generate fixture NATIVE_MODULE_WITH_UNSAFE_OBJECT
- Go to
modules/__test_fixtures__/fixtures.js
and comment all the objects but the one we choose (for exampleNATIVE_MODULE_WITH_UNSAFE_OBJECT
) - Make sure that
module.exports
is exporting that object. - Go to
modules/__test_fixtures__/failures.js
and comment all of them, as we want to work on a single example - Run the tests only in the specific folder, so
yarn jest react-native-codegen -t src/parsers/typescript/modules
This should run only one test, the one we isolated, so you can try to debug the code, eventually adding console.log statements to see what's going on.
packages/react-native-codegen/src/parsers/typescript/modules/index.js
Outdated
Show resolved
Hide resolved
packages/react-native-codegen/src/parsers/parsers-primitives.js
Outdated
Show resolved
Hide resolved
packages/react-native-codegen/src/parsers/flow/modules/index.js
Outdated
Show resolved
Hide resolved
packages/react-native-codegen/src/parsers/typescript/modules/index.js
Outdated
Show resolved
Hide resolved
hasteModuleName, | ||
types, | ||
typeAnnotation, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we pass directly typeAnnotation.id.name
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the emitPartial
requires typeAnnotation
as param :)
6768bd3
to
bafc18a
Compare
@cipolleschi thanks for sharing excellent debugging methods. Though the errors were related to extracting PS: below ci test fail seems unrelated to this diff?? |
bafc18a
to
b904994
Compare
b904994
to
7464edc
Compare
ping @cipolleschi :) |
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
…onTypes` fn - merged TS & Flow parsers' logic for below cases: - `Stringish` - `Int32` - `Double` - `Float` - `UnsafeObject` - `Object` - `Partial` - into an `emitCommonTypes` fn into `parsers-primitives.js` -- 🐨
avoids ternary :) Co-authored-by: Riccardo Cipolleschi <[email protected]>
7464edc
to
a133e23
Compare
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@cipolleschi merged this pull request in 2f25261. |
🎉 @gabrieldonadel & @kyawthura-gg you're unblocked now :) |
… & `commonTypes` cases into `emitCommonTypes` fn (facebook#36450) Summary: > [Codegen 78 - Assigned to Pranav-yadav] It depends on [Codegen 75][Codegen 76][Codegen 77] Extract the logic that emits Partial values in an emitPartial function, which takes the Parsers as parameter. >[Codegen 79 - Assigned to Pranav-yadav] It depends on [Codegen 78] Extract the basic cases logics (case Stringish, case Int32, case Double, ..., case Partial. `Flow` lines and `TypeScript` lines into a function emitCommonTypes in `parsers-primitives.js`. Make sure that the default case returns `null`. Call this function in the default: case `Flow`, `TypeScript` of the `index.js` file: if the function return something, return that from the default case; otherwise if the `emitCommonTypes` returns `null`, keep the current default implementation (throw the error). ### Changes - merged TS & Flow parsers' logic for `Partial` case to `emitPatial` fn - merged TS & Flow parsers' logic for below cases: - `Stringish` - `Int32` - `Double` - `Float` - `UnsafeObject` - `Object` - `Partial` - into an `emitCommonTypes` fn into `parsers-primitives.js` - add **_tests_** for `emitPartial` and `emitCommonTypes` fn's - add `getAnnotatedElementProperties` fn to parser & impl to both TS & Flow parsers ## Changelog: [INTERNAL] [CHANGED] - Merge TS & Flow parsers' logic for `Partial` case to `emitPatial` fn & `commonTypes` cases into `emitCommonTypes` fn Pull Request resolved: facebook#36450 Test Plan: - `yarn lint && yarn run flow && yarn jest react-native` ⇒ � Reviewed By: rshest Differential Revision: D44132308 Pulled By: cipolleschi fbshipit-source-id: f965e85ecc5d94e57ad85334ce565a55c512fde4
… & `commonTypes` cases into `emitCommonTypes` fn (facebook#36450) Summary: > [Codegen 78 - Assigned to Pranav-yadav] It depends on [Codegen 75][Codegen 76][Codegen 77] Extract the logic that emits Partial values in an emitPartial function, which takes the Parsers as parameter. >[Codegen 79 - Assigned to Pranav-yadav] It depends on [Codegen 78] Extract the basic cases logics (case Stringish, case Int32, case Double, ..., case Partial. `Flow` lines and `TypeScript` lines into a function emitCommonTypes in `parsers-primitives.js`. Make sure that the default case returns `null`. Call this function in the default: case `Flow`, `TypeScript` of the `index.js` file: if the function return something, return that from the default case; otherwise if the `emitCommonTypes` returns `null`, keep the current default implementation (throw the error). ### Changes - merged TS & Flow parsers' logic for `Partial` case to `emitPatial` fn - merged TS & Flow parsers' logic for below cases: - `Stringish` - `Int32` - `Double` - `Float` - `UnsafeObject` - `Object` - `Partial` - into an `emitCommonTypes` fn into `parsers-primitives.js` - add **_tests_** for `emitPartial` and `emitCommonTypes` fn's - add `getAnnotatedElementProperties` fn to parser & impl to both TS & Flow parsers ## Changelog: [INTERNAL] [CHANGED] - Merge TS & Flow parsers' logic for `Partial` case to `emitPatial` fn & `commonTypes` cases into `emitCommonTypes` fn Pull Request resolved: facebook#36450 Test Plan: - `yarn lint && yarn run flow && yarn jest react-native` ⇒ � Reviewed By: rshest Differential Revision: D44132308 Pulled By: cipolleschi fbshipit-source-id: f965e85ecc5d94e57ad85334ce565a55c512fde4
Summary
Changes
Partial
case toemitPatial
fnStringish
Int32
Double
Float
UnsafeObject
Object
Partial
emitCommonTypes
fn intoparsers-primitives.js
emitPartial
andemitCommonTypes
fn'sgetAnnotatedElementProperties
fn to parser & impl to both TS & Flow parsersChangelog
[INTERNAL] [CHANGED] - Merge TS & Flow parsers' logic for
Partial
case toemitPatial
fn &commonTypes
cases intoemitCommonTypes
fnTest Plan
yarn lint && yarn run flow && yarn jest react-native
⇒ 🟢