react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[Codegen] Extract throwIfUnsupportedFunctionParamTypeAnnotationParserError function

Open AntoineDoubovetzky opened this issue 3 years ago • 10 comments

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

AntoineDoubovetzky avatar Oct 23 '22 18:10 AntoineDoubovetzky

@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.

Capture d’écran 2022-10-23 à 20 22 51

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?

AntoineDoubovetzky avatar Oct 23 '22 18:10 AntoineDoubovetzky

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

analysis-bot avatar Oct 23 '22 18:10 analysis-bot

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

Base commit: cf5addf423b346dd43204f676c42f0a428f9af9c Branch: main

analysis-bot avatar Oct 23 '22 19:10 analysis-bot

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.

pull-bot avatar Oct 23 '22 19:10 pull-bot

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.

AntoineDoubovetzky avatar Oct 23 '22 20:10 AntoineDoubovetzky

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:

  1. We have the repetition of the if (type == 'something') then throw for each of the invalid types
  2. The logic you highlighted not in the throwIfXXX function.

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! 😊

cipolleschi avatar Oct 24 '22 08:10 cipolleschi

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).

AntoineDoubovetzky avatar Oct 24 '22 08:10 AntoineDoubovetzky

@cipolleschi I updated the PR, I think this is now ready to merge

AntoineDoubovetzky avatar Oct 26 '22 14:10 AntoineDoubovetzky

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

facebook-github-bot avatar Oct 26 '22 15:10 facebook-github-bot

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.

pull-bot avatar Oct 26 '22 15:10 pull-bot

This pull request was successfully merged by @AntoineDoubovetzky in 8c69b6cf781bfdf85cbbd7333bc0a0745d61f411.

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

react-native-bot avatar Oct 28 '22 14:10 react-native-bot