Skip to content

[Codegen] Extract TypeAlias logic of translateTypeAnnotation from the flow and typescript folders in parsers-primitives#34918

Closed
MaeIg wants to merge 4 commits into
facebook:mainfrom
MaeIg:refactor/extract-typeAliasResolution-function
Closed

[Codegen] Extract TypeAlias logic of translateTypeAnnotation from the flow and typescript folders in parsers-primitives#34918
MaeIg wants to merge 4 commits into
facebook:mainfrom
MaeIg:refactor/extract-typeAliasResolution-function

Conversation

@MaeIg
Copy link
Copy Markdown
Contributor

@MaeIg MaeIg commented Oct 10, 2022

Summary

This PR aims to reduce code duplication by extracting typeAliasResolution logic from the flow and typescript folders into a shared parsers-primitives file. It is a task of #34872:

Wrap the TypeAlias resolution lines (Flow, TypeScript) in a proper typeAliasResolution function in the parsers-primitives.js files and replace those lines with the new function.

Changelog

[Internal] [Changed] - Extract TypeAlias logic of translateTypeAnnotation from the flow and typescript folders in parsers-primitives

Test Plan

All tests are passing, with yarn jest react-native-codegen:
image

@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 Oct 10, 2022
Copy link
Copy Markdown
Contributor Author

@MaeIg MaeIg Oct 10, 2022

Choose a reason for hiding this comment

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

I think we should share this type between flow and typescript folders. Unfortunately, we can't share all the logic.

Should i move this type only in packages/react-native-codegen/src/parsers/utils.js? It is the closest common utils file between flow and typescript.

Or, should it be done in another task @cipolleschi?

Copy link
Copy Markdown
Contributor

@cipolleschi cipolleschi Oct 10, 2022

Choose a reason for hiding this comment

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

Yes, please! 😄
If you can move this type up to the parsers/utils.js and reuse it, it would be amazing!

Unfortunately, we can't share all the logic.

What do you mean with this? The type definition seems identical to me. Which logic you feel like we can't share? 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What do you mean with this? The type definition seems identical to me. Which logic you feel like we can't share? 🤔

I mean we can share TypeAliasResolutionStatus which is identical but not resolveTypeAnnotation which uses this type.

If it had been possible, I would have moved everything in react-native-codegen/src/parsers/utils.js 😄

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah yeah... resolveTypeAnnotation is another beast. One of the goals of the umbrella task is to make those two methods as close as possible with incremental changes so that, at some point, we may be able to put them together!

It is expected that it is not the time... yet! :D

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, let's refactor step by step 😁

I moved the type!

@analysis-bot
Copy link
Copy Markdown

analysis-bot commented Oct 10, 2022

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,768,507 +0
android hermes armeabi-v7a 7,169,463 +0
android hermes x86 8,081,647 +0
android hermes x86_64 8,053,150 +0
android jsc arm64-v8a 9,629,226 +0
android jsc armeabi-v7a 8,393,656 +0
android jsc x86 9,578,642 +0
android jsc x86_64 10,171,751 +0

Base commit: e4dff28
Branch: main

Copy link
Copy Markdown
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.

Love this! ❤️ Thank you so much for taking this!!! 😄

@facebook-github-bot
Copy link
Copy Markdown
Contributor

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

@analysis-bot
Copy link
Copy Markdown

analysis-bot commented Oct 10, 2022

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

Base commit: e4dff28
Branch: main

@MaeIg MaeIg force-pushed the refactor/extract-typeAliasResolution-function branch from 580f557 to 2dd655e Compare October 10, 2022 11:38
@facebook-github-bot
Copy link
Copy Markdown
Contributor

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

@cipolleschi
Copy link
Copy Markdown
Contributor

/rebase

MaeIg added 4 commits October 10, 2022 16:25
It is to import other files with strict-local.
We can also use "@flow strict" on all other files, but I don't know if this is what is wanted
as it is not already activated.
@github-actions github-actions Bot force-pushed the refactor/extract-typeAliasResolution-function branch from 2dd655e to 43765f3 Compare October 10, 2022 16:26
@facebook-github-bot
Copy link
Copy Markdown
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
Copy Markdown
Collaborator

This pull request was successfully merged by @MaeIg in 1fc27c4.

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 Oct 10, 2022
@MaeIg MaeIg deleted the refactor/extract-typeAliasResolution-function branch October 10, 2022 17:58
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. hacktoberfest-accepted Merged This PR has been merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants