Skip to content
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

Handle (T) and undefined properly in turbo module component codegen #34693

Closed
wants to merge 5 commits into from

Conversation

ZihanChen-MSFT
Copy link
Contributor

@ZihanChen-MSFT ZihanChen-MSFT commented Sep 14, 2022

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

Test Plan

yarn jest passed in packages/react-native-codegen

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 14, 2022
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Sep 14, 2022
Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking the time for this PR.
I left a few comments and some improvements that we can apply. Let me know what do you think.

I also have the feeling that this PR is doing a little bit too much: support parenthesized types, changing null for undefined, refactoring, error handling... It will be better to split it in multiple PR, what do you think?

Comment on lines +22 to +24
string_optional_key?: (string);
string_optional_value: (string) | null | undefined;
string_optional_both?: (string | null | undefined);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that this probably does not change anything, but I think we should keep also the other syntax, without parenthesis, to make sure that all the use cases are covered.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, if you scroll down the file you will see a lot of similar thing, which remains unchanged. So cases without parenthesis are still covered.

@@ -764,23 +764,23 @@ export interface ModuleProps extends ViewProps {
}>
>;

onDirectEventDefinedInlineOptionalKey?: DirectEventHandler<
onDirectEventDefinedInlineOptionalKey?: (DirectEventHandler<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BubblingEventHandler cases below still covered syntax without parenthesis.

@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,694,713 +36
android hermes armeabi-v7a 7,098,120 +38
android hermes x86 7,997,323 +51
android hermes x86_64 7,969,796 +54
android jsc arm64-v8a 9,565,094 +36
android jsc armeabi-v7a 8,332,078 +46
android jsc x86 9,505,525 +52
android jsc x86_64 10,097,156 +72

Base commit: ab5f26b
Branch: main

@ZihanChen-MSFT
Copy link
Contributor Author

I also have the feeling that this PR is doing a little bit too much: support parenthesized types, changing null for undefined, refactoring, error handling... It will be better to split it in multiple PR, what do you think?

Hi, @cipolleschi , in general I do think smaller PR is better, but in this case, the "first event type argument could be void->undefined or null" one is just one line of code and it is embedded in the refactored code, and if I split into 2 PR it will get conflict no matter which one is merged first. So in this particular case I do think combining them in one is better.

@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: ab5f26b
Branch: main

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @ZihanChen-MSFT in 205cc9b.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Sep 22, 2022
@ZihanChen-MSFT ZihanChen-MSFT deleted the ts-rncodegen8 branch September 22, 2022 21:04
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
…acebook#34693)

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: facebook#34693

Test Plan: `yarn jest` passed in `packages/react-native-codegen`

Reviewed By: NickGerleman

Differential Revision: D39647075

Pulled By: cipolleschi

fbshipit-source-id: 8e1df2b54aab37b7151d0bf74260e2eba0602777
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants