-
Notifications
You must be signed in to change notification settings - Fork 25k
[Codegen 101] Enrich getCommandProperties with the parser object #36500
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 101] Enrich getCommandProperties with the parser object #36500
Conversation
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.
That's a very good starting points.
There are a few other improvements we can do:
- Flow, line 126 (it doesn't let me add a comment at that line) and Typescript, line 126: that check can go in the
Parserobject. So the Flow parser can returnInterfaceDeclarationand the TS parser can returnTSInterfaceDeclaration - Line 134: same as above.
Parsercan have abodyPropertiesfunction that, given a typeAlias returnsbody.propertiesfor Flow andbody.bodyfor TS. - Line 141: we can add the
propertyNamesfunction to the parsers that extract the right array of property names. - After these changes, the two functions should be actually identical and we can move it in a single file in
parser-commons.js, for example.
What do you think?
Base commit: d9f7c4c |
|
Moved propertyName to parser common file. |
|
Yes and no. If property name has to switch over the language, it should not accept a Does this make sense? |
|
I meant these lines. Sorry for confusion. In Flow, let properties;
try {
properties = typeAlias.body.properties;
} catch (e) {
throw new Error(
`Failed to find type definition for "${commandTypeName}", please check that you have a valid codegen flow file`,
);
}In TypeScript, let properties;
try {
properties = typeAlias.body.body;
} catch (e) {
throw new Error(
`Failed to find type definition for "${commandTypeName}", please check that you have a valid codegen typescript file`,
);
} |
|
yes, the check should become for both of them: let properties = parser.bodyProperties(typeAlias);
if (!properties) {
throw new ....
} |
|
Added |
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.
Great job! It looks good to me!
|
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
/rebase |
|
@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 969a8d0. |
Summary: > [Codegen 101] The code of getCommandProperties is almost identical in [Flow](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/flow/components/index.js#L128) and [TS](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/typescript/components/index.js#L129). There are small differences between flow/ts, so we need for it to accept a Parser object. Enrich the parser object with the required methods if necessary. ## Changelog: [Internal] [Changed] - Enrich getCommandProperties with the parser object Pull Request resolved: facebook#36500 Test Plan: `yarn test react-native-codegen` Reviewed By: cortinico Differential Revision: D44415265 Pulled By: cipolleschi fbshipit-source-id: ed13b553a6f782beb0f1aec79bd17d865a96fac9
Summary: > [Codegen 101] The code of getCommandProperties is almost identical in [Flow](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/flow/components/index.js#L128) and [TS](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/typescript/components/index.js#L129). There are small differences between flow/ts, so we need for it to accept a Parser object. Enrich the parser object with the required methods if necessary. ## Changelog: [Internal] [Changed] - Enrich getCommandProperties with the parser object Pull Request resolved: facebook#36500 Test Plan: `yarn test react-native-codegen` Reviewed By: cortinico Differential Revision: D44415265 Pulled By: cipolleschi fbshipit-source-id: ed13b553a6f782beb0f1aec79bd17d865a96fac9
Summary
Changelog:
[Internal] [Changed] - Enrich getCommandProperties with the parser object
Test Plan
yarn test react-native-codegen