react-native
react-native copied to clipboard
[Codegen] Extract throwIfUnsupportedFunctionParamTypeAnnotationParserError function
Summary
This PR is a task from https://github.com/facebook/react-native/issues/34872:
Extract the UnsupportedFunctionParamTypeAnnotationParserError in its own throwing function (if it does not exists already) and reuse that function passing a proper type. Then, refactor the code using a dictionary and avoiding the three different ifs in both parsers.
Changelog
[Internal] [Changed] - Extract the UnsupportedFunctionParamTypeAnnotationParserError in its own throwing function in error-utils
Test Plan
@cipolleschi I still need to do the second part of the task ("Then, refactor the code using a dictionary and avoiding the three different ifs in both parsers."), but I have some troubles with Flow.
Flow doesn't understand anymore that paramTypeAnnotation can't be of type VoidTypeAnnotation nor PromiseTypeAnnotation.
I tried to use predicate functions but I didn't manage to make it work in this case. I don't like the idea of adding a $FlowFixMe comment. Do you have any idea?
| Platform | Engine | Arch | Size (bytes) | Diff |
|---|---|---|---|---|
| android | hermes | arm64-v8a | 7,066,076 | +73,448 |
| android | hermes | armeabi-v7a | 6,470,155 | +101,198 |
| android | hermes | x86 | 7,377,755 | -27,147 |
| android | hermes | x86_64 | 7,348,765 | +79,576 |
| android | jsc | arm64-v8a | 8,923,088 | +63,147 |
| android | jsc | armeabi-v7a | 7,689,029 | +90,911 |
| android | jsc | x86 | 8,869,884 | -47,661 |
| android | jsc | x86_64 | 9,462,806 | +61,643 |
Base commit: cf5addf423b346dd43204f676c42f0a428f9af9c Branch: main
| Platform | Engine | Arch | Size (bytes) | Diff |
|---|---|---|---|---|
| ios | - | universal | n/a | -- |
Base commit: cf5addf423b346dd43204f676c42f0a428f9af9c Branch: main
PR build artifact for 3e1326d62f0a9b778c32428886735dca046092ec is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.
I searched if there were other places where we encountered the same problem. I believe it is the case in this PR https://github.com/facebook/react-native/pull/34917, and I see that the if(XXX) is not in the throwIfXXX function, but I feel like it's losing the point of extracting the function.
Hi @AntoineDoubovetzky, thanks for the comment.
I understand what you are trying to say and I completely agree. However, I think we have two orders of problems:
- We have the repetition of the
if (type == 'something') then throwfor each of the invalid types - The logic you highlighted not in the
throwIfXXXfunction.
To keep things as simple as possible, I tried to split the problem in two steps: the PR you linked was addressing only the first one and I think it's fine: we can have another task for the second step.
Does this reasoning make sense to you?
For your task, you can tackle both points together, if you feel it! 😊
I'll do the first one, for the second one I have a Flow error that I didn't manage to fix yet (https://github.com/facebook/react-native/pull/35057#issuecomment-1288170962).
@cipolleschi I updated the PR, I think this is now ready to merge
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
PR build artifact for 232c85288b4dbc0340f106fa587c13909f237525 is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.
This pull request was successfully merged by @AntoineDoubovetzky in 8c69b6cf781bfdf85cbbd7333bc0a0745d61f411.
When will my fix make it into a release? | Upcoming Releases