forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Codegen: Generate ObjC structs for type aliases
Summary: **Motivation:** Match the old codegen's behavior when generating structs for type alias derived objects. **Problem description:** Take, for example, the following spec: ``` export type MyTypeAlias = { /* ... */ } export interface Spec extends TurboModule { // ... +myMethod: (paramName: MyTypeAlias) => void; // ... } ``` The codegen needs to generate a struct to expose the properties of the type alias object. The codegen was producing the following output: ``` - (void)myMethod:(JS::MyModule::SpecMyMethodParamName &)paramName; ``` ...which does not match the output from the original codegen: ``` - (void)myMethod:(JS::MyModule::MyTypeAlias &)paramName; ``` The original codegen generates a struct using the type alias name, while the new codegen was generating a struct that uses a combination of the property and parameter names. Now that type alias names are exposed in the schema, the new codegen can match the original codegen's behavior. **De-duplication of structs:** Prior to these changes, type aliases were expanded into regular object types. This meant that any spec that used a type alias more than once would lead to redundant structs getting created. With these changes, we only generate the one struct per type alias, matching the old codegen. **Expansion of type aliases:** A new type was introduced in D22200700 (facebook@e261f02), TypeAliasTypeAnnotation: ``` export type TypeAliasTypeAnnotation = $ReadOnly<{| type: 'TypeAliasTypeAnnotation', name: string, |}>; ``` This type may now appear in several locations where a `{| type: 'ObjectTypeAnnotation', properties: [] |}` otherwise would have been used. A `getTypeAliasTypeAnnotation` function is introduced which, given an alias name and an array of aliases provided by the module, will produce the actual object type annotation for the given property parameter. Changelog: [Internal] Reviewed By: RSNara Differential Revision: D22244323 fbshipit-source-id: 125fbf0d6d887bd05a99bf8b81b30bdda4f1682b
- Loading branch information
1 parent
e255748
commit 7e7706c
Showing
14 changed files
with
2,504 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.