-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
[Codegen 86] Use buildPropSchema
from parser-commons
#37043
Conversation
dc157a3
to
55e12d6
Compare
Base commit: 33e0521 |
55e12d6
to
04d2dd1
Compare
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
For what I can see, you are feeding the callbacks in the right way. There are some issues with the typings, though, that we have to iron out. If you clic the CircleCI jobs, you can see the errors, like here. For example:
|
Ok, i figured out what's the problem. We basically have a circular reference that cannot be resolved by Flow. Specifically:
I have to think about how to break that, but I don't think we can go down this path, unfortunately. :( |
I found a way to make it work. Basically, we have a problem here: // in parser-commons.js
function buildPropSchema(
// params
): ?NamedShape<PropTypeAnnotation> {
// good lines...
return {
name,
optional,
typeAnnotation: getTypeAnnotation(
name,
typeAnnotation,
defaultValue,
withNullDefault,
types,
buildPropSchema, // <-- this don't work
),
};
} Looking better at the problem, the reason why it doesn't work is because So, Flow is properly complaining that it is missing a couple of parameters to make it work. 😅 The way to solve this is to provide a function signature which matches. So, we can do something like: // in parser-commons.js
function buildPropSchema(
// params
) => $FlowFixMe,
): ?NamedShape<PropTypeAnnotation> {
// good lines...
const wrappedBuildSchema = (passedProps: PropAST, passedTypes: TypeDeclarationMap): $FlowFixMe => {
buildPropSchema(passedProps, passedTypes, getSchemaInfo, getTypeAnnotation);
}
return {
name,
optional,
typeAnnotation: getTypeAnnotation(
name,
typeAnnotation,
defaultValue,
withNullDefault,
types,
wrappedBuildSchema, // <-- this is different: it calls the function above, with all the params
),
};
} the execution of If why this is happening is not clear, I'll be happy to try and explain it better or in a different way! 😄 |
f959485
to
b0912dd
Compare
Thank you for the investigation and the suggestion! Now, it is time to resolve the test failures... 💪 yarn jest react-native-codegen
|
b0912dd
to
7707017
Compare
types: TypeDeclarationMap, | ||
buildSchema: (property: PropAST, types: TypeDeclarationMap) => $FlowFixMe, | ||
) => $FlowFixMe, | ||
): ?NamedShape<PropTypeAnnotation> { |
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.
Error ----------------------------------- packages/react-native-codegen/src/parsers/typescript/components/props.js:112:7
Cannot return object literal because null or undefined [1] is incompatible with `NamedShape` [2] in array element of
property `props`. [incompatible-return]
packages/react-native-codegen/src/parsers/typescript/components/props.js:112:7
112| buildPropSchema(property, types, getSchemaInfo, getTypeAnnotation),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
References:
packages/react-native-codegen/src/parsers/parsers-commons.js:845:4
845| ): ?NamedShape<PropTypeAnnotation> {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1]
packages/react-native-codegen/src/parsers/typescript/components/props.js:74:25
74| props: $ReadOnlyArray<NamedShape<PropTypeAnnotation>>,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [2]
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 took this code from flow one tho
https://github.com/facebook/react-native/pull/37043/files#diff-5cbd2ff460e869762c61aabc2adca0c30f77d52c181a2c1c807532e64ce0e9e2L28
7707017
to
5ef4d30
Compare
Hi @ken0nek, could you please:
Thank you so much! |
5ef4d30
to
4eed951
Compare
Sure! Finished rebasing and resolving conflicts. Will look into the errors on CI. |
buildSchema: (property: PropAST, types: TypeDeclarationMap) => $FlowFixMe, | ||
) => $FlowFixMe, | ||
): ?NamedShape<PropTypeAnnotation> { | ||
const info = getSchemaInfo(property, types); |
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.
Have to handle the nullability of getSchemaInfo
@ken0nek gentle ping on this. Do you think you might be able to address these issues by the end of this week? |
Thank you for checking in. Sorry to say but that might be difficult... I don't want to block other codegen tasks, please take this task if possible 🙏 I wish I could contribute to the repository quickly and effectively... |
Given you make most of the work, I can import it and finish up the work myself. It won't take much. Is that ok for you? If yes, could you just set the PR as |
Sure, thank you for your help and support! |
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@cipolleschi merged this pull request in 0212179. |
Thank you for handling this pull request! Learned a lot by reading 0212179 |
Summary:
part of #34872
ref: #34872 (comment)
Changelog:
[Internal] [Changed] - Use
buildPropSchema
from parser-commonsTest Plan:
yarn jest react-native-codegen
pass