-
Notifications
You must be signed in to change notification settings - Fork 25k
[Codegen] Extract throwIfUnsupportedFunctionParamTypeAnnotationParserError function #35057
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
Conversation
2ca7834 to
3e1326d
Compare
|
@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 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. |
Base commit: cf5addf |
Base commit: cf5addf |
|
PR build artifact for 3e1326d is ready. |
|
I searched if there were other places where we encountered the same problem. I believe it is the case in this PR #34917, and I see that the |
|
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:
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 (#35057 (comment)). |
cipolleschi
left a comment
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.
Amazing, thank you for taking this and to look through the codebase.
I left a comment to improve it further and it could perhaps solve the other problem as well.
| throwIfUnsupportedFunctionParamTypeAnnotationParserError( | ||
| hasteModuleName, | ||
| flowParam.typeAnnotation, | ||
| paramTypeAnnotation.type, | ||
| paramName, | ||
| 'PromiseTypeAnnotation', | ||
| ); |
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.
What about saving some more lines (deleting line from 453 to 459)with this:
| throwIfUnsupportedFunctionParamTypeAnnotationParserError( | |
| hasteModuleName, | |
| flowParam.typeAnnotation, | |
| paramTypeAnnotation.type, | |
| paramName, | |
| 'PromiseTypeAnnotation', | |
| ); | |
| const forbiddenTypes = new Set(['VoidTypeAnnotation', 'PromiseTypeAnnotation']); | |
| const currentType = paramTypeAnnotation.type; | |
| if (forbiddenTypes.has(currentType)) { | |
| throwIfUnsupportedFunctionParamTypeAnnotationParserError( | |
| hasteModuleName, | |
| flowParam.typeAnnotation, | |
| paramTypeAnnotation.type, | |
| paramName, | |
| currentType, | |
| ); | |
| } |
This is better because, if in the future we want to forbid more type, we can just work on the Set instead of make one call for each.
Perhaps, with this approach, you may also be able to solve the Flow problem.
What do you think?
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.
I tried to use a Set but Flow couldn't infer that paramTypeAnnotation.type could not equal VoidTypeAnnotation or PromiseTypeAnnotation so I had the same Flow error when calling wrappNullable as before (#35057 (comment)).
The only solution I found is to replace the Set with multiple OR conditions and to add an early return.
…ionParserError function
…ramTypeAnnotationParserError
3e1326d to
232c852
Compare
|
@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 232c852 is ready. |
|
This pull request was successfully merged by @AntoineDoubovetzky in 8c69b6c. When will my fix make it into a release? | Upcoming Releases |
…tion (facebook#35057) Summary: This PR is a task from facebook#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 <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [Internal] [Changed] - Extract the UnsupportedFunctionParamTypeAnnotationParserError in its own throwing function in error-utils Pull Request resolved: facebook#35057 Reviewed By: lunaleaps Differential Revision: D40721099 Pulled By: cipolleschi fbshipit-source-id: af5e4cd275d0049047d35660559b94a27e660e40

Summary
This PR is a task from #34872:
Changelog
[Internal] [Changed] - Extract the UnsupportedFunctionParamTypeAnnotationParserError in its own throwing function in error-utils
Test Plan