-
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
☂️ Improving Codegen #34872
Comments
Hi @cipolleschi I would like to help with the |
Hey @cipolleschi I'd like to work on following task: |
Hey @cipolleschi, thank you for this umbrella issue!
|
Hi @cipolleschi, I would like to try helping with this task:
|
Sounds like a good place to log what I am going to do next for the TypeScript part: ToDo
Done
And eventually, since codegen parses TypeScript and Flow using babel, it is no reason to implement them separately. In order to do that, I will try to refactor the TypeScript part and make it more generalized, to be ready to accept Flow AST in a low effort. |
Hi @cipolleschi. I would like to work on the following task.
|
Hi @cipolleschi. I would like to pick this one too: |
Hi @cipolleschi I would like to help with the task below as well
|
@gabrieldonadel these are supposed to be a different task for each error. The logic to decide whether to throw each error is slightly different from each other. Is it ok if we start with the first one? |
Ohh sorry @cipolleschi , I didn't notice that each of these was one task, can I have the |
Hi @cipolleschi I would like to help with the following task:
|
Hi @cipolleschi, I would like to work on the following task
|
Hi @cipolleschi, I would like to take this up
|
Hi @cipolleschi, I would like to work on the following task
|
Hi @cipolleschi, I would like to work on the following task Extract each individual exception to a separate function inside an error-utils.js file. Each function should accept an extra parser parameter, throw the proper error based on the parser and use it in the Flow parser and in the TypeScript one. All these errors can be found in the buildModuleSchema function (Flow, Typescript) The list of exceptions to handle is:
|
Hi @cipolleschi I would like to take the following issue:
|
Hi @mohitcharkha! before taking another task, please open a PR on the one already assigned. You are currently assigned to fixing the |
Small update: given the interest the initiative is having, I added some more tasks for people to pick up. 🎉 🎉 Thank you to every one of you for the amazing work! 😄 |
…34879) Summary: This PR reduces code duplication by ```extracting the modules/schema.js from the flow and typescript folders in a shared parsers-commons.js file. Then, have the two parsers use the same wrapModuleSchema function for modules``` as part of #34872 ## 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] - Extracts the modules/schema.js from the flow and typescript folders in a shared file. Pull Request resolved: #34879 Test Plan: run ```yarn jest react-native-codegen``` <img width="788" alt="image" src="https://user-images.githubusercontent.com/34857453/194232470-3ae3b99a-2556-48da-aac6-20ffc95f90a0.png"> Reviewed By: robhogan Differential Revision: D40143266 Pulled By: robhogan fbshipit-source-id: 417a5456c8099ad2761617e2be7cf8306c7d9ec4
Hello @cipolleschi! I'd like to work on the following issue:
edit: seems like this pr needs to be merged first: #34896 |
Hello @cipolleschi, this umbrella issue is awesome ! I would like to work on the following task:
|
Summary: [Codegen 130] This PR add a `getLiteralValue` function to the Parser interface, which returns the literal value of an union represented, given an option. as requested on #34872 ## Changelog: [INTERNAL] [ADDED] - Add `getLiteralValue` function to codegen Parser Pull Request resolved: #38651 Test Plan: Run `yarn jest react-native-codegen` and ensure CI is green Reviewed By: cipolleschi Differential Revision: D47912960 Pulled By: rshest fbshipit-source-id: d9426fef4c0f92c5244d5c4c72202ec29099b76e
Summary: [Codegen 135] This PR introduces `getPaperTopLevelNameDeprecated` to parser base class and abstracts the logic out of typescript and parser events as requested on #34872 ## Changelog: [Internal] [Changed] - Add `getPaperTopLevelNameDeprecated` to parser base class and update usages. Pull Request resolved: #38683 Test Plan: Run `yarn jest react-native-codegen` locally and ensure CI is green ## Screenshot of test passing locally: <img width="1060" alt="Screenshot 2023-07-30 at 10 04 24 AM" src="https://github.com/facebook/react-native/assets/64726664/3f61377b-9f44-45e8-bece-d4fd6bcc4567"> Reviewed By: cipolleschi Differential Revision: D47902816 Pulled By: rshest fbshipit-source-id: 6fab53e02cfc3f0aaa3ffd795c3fe1d2f723e060
@cipolleschi : codegen-135 is merged. |
Summary: [Codegen 131] This PR add a function `emitUnionProp` to the parser-primitives, as requested on #34872 ## Changelog: [INTERNAL] [ADDED] - Add `emitUnionProp` function to parser-primitives Pull Request resolved: #38705 Test Plan: `yarn test react-native-codegen` Reviewed By: christophpurrer Differential Revision: D47921708 Pulled By: rshest fbshipit-source-id: c2c081c6317928e5eb8b0c1d0640c7b7f40a4b0b
Summary: > [Codegen 134 - Assigned to cloudpresser] Create a function getTypeAnnotationName(typeAnnotation) in the Parser base class. Implement it using [this code for Flow](https://github.com/facebook/react-native/blob/d8ced6f8953cd896471983714e722caf50783960/packages/react-native-codegen/src/parsers/flow/components/events.js#L211) and [this code for Typescript](https://github.com/facebook/react-native/blob/d8ced6f8953cd896471983714e722caf50783960/packages/react-native-codegen/src/parsers/typescript/components/events.js#L223). Replace the callsites with the new function. This is part of #34872 bypass-github-export-checks ## Changelog: [INTERNAL] [ADDED] - getTypeAnnotationName(typeAnnotation) in parser Pull Request resolved: #37580 Test Plan: `yarn jest packages/react-native-codegen` > new tests written, as well as coverage from existing tests Reviewed By: rshest Differential Revision: D46439051 Pulled By: cipolleschi fbshipit-source-id: c0ccddc11b56d77788b4957381fbbaa82d992b01
Only 2 more tasks to complete, guys! |
Summary: Part of #34872 > Extract the content of the if branches that handle the EventHandlers ([Flow](https://github.com/facebook/react-native/blob/e133100721939108b0f28dfa9f60ac627c804018/packages/react-native-codegen/src/parsers/flow/components/events.js#L131-L151), [TypeScript](https://github.com/facebook/react-native/blob/e133100721939108b0f28dfa9f60ac627c804018/packages/react-native-codegen/src/parsers/typescript/components/events.js#L150-L171)) into a handleEventHandler function in parsers-commons.js. This will take a name, a typeAnnotation, a parser and a findEventArgumentsAndType function as parameters. Use the switch based approach from TypeScript. ## Changelog: [Internal][Changed]: Extract the content into handleEventHandler Pull Request resolved: #38805 Test Plan: `yarn test react-native-codegen` Reviewed By: rshest Differential Revision: D48100350 Pulled By: cipolleschi fbshipit-source-id: 5de6deacd50e87ea0ec96147fff7c14ba55e5368
Summary: [Codegen 119] This PR introduces `emitBuildEventSchema` to parser commons and abstracts the logic out of typescript and parser events as requested on #34872 ## Changelog: [Internal] [Changed] - Add `emitBuildEventSchema` to parser commons and update usages. Pull Request resolved: #38810 Test Plan: Run `yarn jest react-native-codegen` locally and ensure CI is green ## Screenshot of test passing locally: <img width="1047" alt="Screenshot 2023-08-07 at 8 03 49 AM" src="https://github.com/facebook/react-native/assets/64726664/ab87f004-d9f8-4b5f-800b-0e724430301f"> Reviewed By: rshest Differential Revision: D48155051 Pulled By: cipolleschi fbshipit-source-id: a3db3f4783d60681b366a871b1d2ee32eb864bc0
Hey everyone! Thank you so much for contributing to react native and to work on these tasks with so much passion and love. There is so much more to do, to simplify the parsing of Components and then to work on the Generators! Thank you so much to: @gabrieldonadel, @tarunrajput, @AntoineDoubovetzky, @matiassalles99, @dhruvtailor7, @Marcoo09, @mohitcharkha, @vinayharwani13, @mdaj06, @youedd, @harshsiri110, @ZihanChen-MSFT, @ken0nek, @MaeIg, @Naturalclar, @dakshbhardwaj, @Pranav-yadav, @kyawthura-gg, @siddarthkay, @yux-m, @marcocaldera, @Shubham1429, @cloudpresser, @ahmadao2214, @foestauf, @Zwem, @Randall71, @branaust, @frankcalise, @rota-rossi I hope I haven't forget anyone! |
Description
Hi everyone!
This is an umbrella issue to collect a set of tasks aimed to improve the code in the react-native-codegen package.
Codegen is a pillar for the New Architecture and is part of the core developer experience. We believe that everyone would benefit from a clear and maintainable codebase, hence this umbrella issue to help us cleanup and restructure some of its components.
The codegen internals
Codegen work with a 2-steps process:
Codegen package is divided in three high-level folders:
The first step of this imrpovement effort will focus on the Parsers.
Parsers
The parsers folders contains subfolders to parse Flow and TypeScript specs. The two folders have a very similar structure:
index.js
,errors.js
andutils.js
There are different levels of code duplication we want to reduce.
How to Test
It’s crucial that you test the changes you submit. The proper way of doing this is:
__tests__
at the same level of the file you added/modified.<your-file>-tests.js
file (if it doesn't exists). An example test is this one. Make sure to:Once you implemented your changes, you can run the tests locally by following these steps:
You can find more documentation on Jest, our testing framework, here (https://jestjs.io/).
The Tasks
The following is a list of tasks we need to execute to improve the code quality of this tool. The list is a living one: the more we improve with the situation, the more patterns we can discover. Whenever we found some pattern that we can add, we will attach this to the list.
If you want to tackle some specific task which is not listed, feel free to post a comment with a brief description of the task and I'll make sure to add it to the list of tasks so it is tracked.
Please comment below if you're willing to take the stance on any of those task and wait for a confirmation before start working on it. Please note that if you claim a task, but don't submit a PR within 2 week, we're going to free up that task for someone else.
Extract theCommit 7227bdeerror.js
file from the flow and typescript folders into anerror.js
file in their parent folder. Then, have the two parsers use the sameParserError
Assigned to @gabrieldonadel
Extract theCommit 35556dbmodules/schema.js
from the flow and typescript folders in a sharedparsers-commons.js
file. Then, have the two parsers use the samewrapModuleSchema
function for modules.Assigned to @tarunrajput
Extract theCommit 24efebfmodules/utils.js
from the flow and typescript folders in a sharedparsers-commons.js
file. Then, have the two parsers use the samewrapModuleSchema
function for modules.assigned to @AntoineDoubovetzky
[Assigned to @matiassalles99] Extract theUnsupportedArrayElementTypeAnnotationParserError
in its own throwing function and reuse that function passing a proper type. The error is thrown at lines132
,141
and150
in both Flow and TypeScript parsers.Refactor the code using a dictionary and avoiding the three differentif
s in the Flow parserRefactor the code using a dictionary and avoiding the three differentCommit cc311ffif
s in the TS parser[Assigned to @dhruvtailor7]Extract theUnsupportedObjectPropertyValueTypeAnnotationParserError
in its own throwing function and reuse that function passing a proper type. The error is thrown at lines281
,290
and299
in both Flow and TypeScript parsers.Refactor the code using a dictionary and avoiding the three differentif
s in the Flow parserRefactor the code using a dictionary and avoiding the three differentCommit aba6be6if
s in the TS parserExtract all the errors in theCommit 7b345bcflow/module/errors.js
and in thetypescript/module/errors.js
into a singleparser/errors.js
file. All the errors must drop the correspondingFlow
orTypescript
token in the name and take an extralanguage
parameter in the constructor. Also, rename thehasteModuleName
parameter tonativeModuleName
.Assigned to @tarunrajput
error-utils.js
file. Each function should accept an extra parser parameter, throw the proper error based on the parser and use it in the Flow parser and in the TypeScript one. All these errors can be found in thebuildModuleSchema
function (Flow, Typescript) The list of exceptions to handle is:[Assigned to @gabrieldonadel ]Commit c9338c4InterfaceNotFound
[Assigned to @Marcoo09 ]Commit f628edcMoreThanOneModule
[Assigned to @mohitcharkha]Commit 9fb3700MisnamedModuleFlowInterfaceParserError
[Assigned to @vinayharwani13]Commit a33f672UnusedModuleFlowInterfaceParserError
[Assigned to @mohitcharkha]Commit ab22e3aMoreThanOneModuleRegistryCallsParserError
[Assigned to @dakshbhardwaj]Commit 76c5b6fIncorrectModuleRegistryCallArityParserError
[Assigned to @mdaj06]Commit bb519ecIncorrectModuleRegistryCallArgumentTypeParserError
[Assigned to @dhruvtailor7]Commit 1e15e21UntypedModuleRegistryCallParserError
[Assigned to @harshsiri110]Commit bb519ecIncorrectModuleRegistryCallTypeParameterParserError
[Assigned to @ZihanChen-MSFT] Support intersection of object types,Commit 813fd04{...a, ...b, ...}
in Flow is equivalent toa & b & {...}
in TypeScript, the order and the form is not important.CodegenSchema.js
toCodegenSchema.d.ts
, and add type descriptions for exposed functions.CodegenSchema.js
component property types are better to be defined in recursion, not to repeat everything in Array again.[Assigned to @AntoineDoubovetzky] Extract the functionCommit 790f40cassertGenericTypeAnnotationHasExactlyOneTypeParameter
(Flow TypeScript) into a single function in theparsers-common.js
file and replace its invocation with this new function.Extract the content of the case 'RootTag' (Flow, TypeScript) into a singleCommit 5f05b07emitRootTag
function in theparsers-primitives.js
file. Use the new function in the parsers.Assigned to @MaeIg
Extract the content of the case 'Promise' (Flow, TypeScript) into a singleCommit 966f3cdemitPromise
function in theparsers-primitives.js
file. Use the new function in the parsers.Assigned to @AntoineDoubovetzky
[Assigned to @gabrieldonadel] Extract the content of the case 'Stringish' (Flow, TypeScript) into a singleCommit 305f7c3emitStringish
function in theparsers-primitives.js
file. Use the new function in the parsers.Extract the content of the case 'Int32' (Flow, TypeScript) into a singleCommit db8c11demitInt32
function in theparsers-primitives.js
file. Use the new function in the parsers.Assigned to @Naturalclar
[Assigned to @AntoineDoubovetzky]Extract the content of the case 'Double' (Flow, TypeScript) into a singleCommit 3ab7ef2emitDouble
function in theparsers-primitives.js
file. Use the new function in the parsers.[Assigned to @gabrieldonadel]Extract the content of the case 'Float' (Flow, TypeScript) into a singleCommit: 87d6580emitFloat
function in theparsers-primitives.js
file. Use the new function in the parsers.[Assigned to @Marcoo09] Extract the content of the case 'Object' (Flow, TypeScript) into a singleCommit fd4451eemitObject
function in theparsers-primitives.js
file. Use the new function in the parsers.[Assigned to @MaeIg] Wrap the TypeAlias resolution lines (Flow, TypeScript) in a propertypeAliasResolution
function in theparsers-primitives.js
files and replace those lines with the new function.[Assigned to @tarunrajput] Extract the content of the case 'BooleanTypeAnnotation' (Flow, TypeScript) into a singleCommit 7a2e346emitBoolean
function in theparsers-primitives.js
file. Use the new function in the parsers.[Assigned to @youedd] Extract the content of the case 'NumberTypeAnnotation' (Flow, TypeScript) into a singleCommit 54fc62cemitNumber
function in theparsers-primitives.js
file. Use the new function in the parsers.[Assigned to @youedd] Extract the content of the case 'VoidTypeAnnotation' (Flow, TypeScript) into a singleCommit b3219feemitVoid
function in theparsers-primitives.js
file. Use the new function in the parsers.[Assigned to @ken0nek]Extract the content of the case 'StringTypeAnnotation' (Flow, TypeScript) into a singleCommit eda90e5emitString
function in theparsers-primitives.js
file. Use the new function in the parsers.[Assigned to @mohitcharkha] Extract the content of the case 'FunctionTypeAnnotation' (Flow, TypeScript) into a singleCommit c403cd4emitFunction
function in theparsers-primitives.js
file. Use the new function in the parsers.[Assigned to @MaeIg] Extract the function createParserErrorCapturer (Flow TypeScript) into a single function in the parsers/utils.js file and replace its invocation with this new function.Commit 38fcafe[Assigned to @AntoineDoubovetzky] Extract the function visit (Flow TypeScript) into a single function in the parsers/utils.js file and replace its invocation with this new function.Commit 3c8d678[Assigned to @AntoineDoubovetzky] Extract the function isModuleRegistryCall (Flow TypeScript) into a single function in the parsers/utils.js file and replace its invocation with this new function.Commit: 83e2126[Assigned to @dhruvtailor7] This task is more advanced than the others and a 2-steps tasks. First, extract thevisitor
object into a separate dictionary in the same file (Flow, TypeScript. The signature of thevisit
method is in these links: Flow, TypeScript). Then, factor out the thegetConfigType
function (Flow, TypeScript) into theparsers/utils.js
file.[Assigned to @MaeIg] This task is more advanced than the others. Extract theCommit 8f484c3switch(configType)
block (Flow, TypeScript) from thebuildSchema
function into a new function in theparsers/utils.js
file and use it in the two functions. Note that the new function must accept some callbacks to wrapModule/ComponentSchema and to buildModule/ComponentSchema.[Assigned to @gabrieldonadel] ExportCommit 376ffacparseFile
(Flow, TypeScript) in to aparseFile
function inparsers/utils.js
. Note that the function should accept a callback tobuildSchema
properly.[Assigned to @vinayharwani13] This task is much simple than the others, it just moves a type and there is no logic. Export theCommit 2934399TypeDeclarationMap
type (Flow, TypeScript) into a single type in theparsers/utils.js
file.[Assigned to @dakshbhardwaj] Extract theCommit 1eaa092nullGuard
function (Flow, TypeScript) into a function in theparsers-utils.js
file and use it in the other parsers.[Assigned to @MaeIg] Wrap the content of theCommit c388e6ccase Array:
andcase ReadOnlyArray
in Flow into a separate function, as it is for the TypeScript parser. This will enable us to unify the two parsers in a later step.[Assigned to @gabrieldonadel] This task is more advanced than the others Create a function to unify theCommit ea55e3bdefault:
case (Flow, TypeScript) into theparser-commons.js
file and use it in the two parsers. For theif (CxxOnly
statement, we may accept an OR betweenEnumDeclaration
andTSEnumDeclaration
. The function should accept aParserType
parameter to implement the proper logic to extract thememberType
variable. Ideally, we should create a couple of supporting functions to implement those logics.[Assigned to @youedd] This task is more advanced than the others Create a function to unify theCommit 0627cd6unionType
and theTSUnionType
. This task may share some logic from the previous task. The function should accept aParserType
parameter to implement the proper logic to extract thememberType
variable. Ideally, we should create a couple of supporting functions to implement those logics.[Assigned to @tarunrajput] Create a functionCommit b87d371emitMixedTypeAnnotation
into theparsers-commons.js
file to put together this code from Flow and TypeScript.[Assigned to @harshsiri110] Extract the logic that throw theCommit 3247436UnsupportedFunctionReturnTypeAnnotationParserError
(Flow, TypeScript) into a new function in the theparsers/error-utils.js
file. The function should encapsulate the logic that decide whether to throw the error or not. Please reuse theUnsupportedFunctionReturnTypeAnnotationParserError
that has already been exported in theparsers/errors.js
file.[Assigned to @mohitcharkha] Extract the logic that throws theCommit f645404UnsupportedModulePropertyParserError
(Flow, TypeScript) into a new function in theparsers/error-utils.js
file. It should take a parameterParserType
to discriminate the logic of the two. Please reuse theUnsupportedModulePropertyParserError
that has already been exported in theparsers/errors.js
file.[Assigned to @youedd] Extract theCommit 633498fnameToValidate
logic (Flow, TypeScript) into a shared function into theparser/utils.js
file. Notice that you may need a callback to update the cxx boolean.[Assigned to @ZihanChen-MSFT] Support function signature along with function type properties in commands.Commit ae1d54b[Assigned to @MaeIg] Extract theCommit 3f2691cparseFile
function in theparsers-commons.js
file to a top levelbuildSchema
function which takes additional parameters to properly parse the content, get the config type and to build the schema, based on the language used.[Assigned to @MaeIg] Extract theCommit 4628150buildSchema
function (Flow, TypeScript) in theparsers-commons.js
file to a top levelbuildSchema
function which takes additional parameters to properly parse the content, get the config type and to build the schema, based on the language used.[Assigned to @Pranav-yadav ] Note: this task depends on "Extract theCommit 5a20bd5UnsupportedArrayElementTypeAnnotationParserError
" Extract the functiontranslateArrayTypeAnnotation
(Flow, TypeScript) into a funtion in theparsers-primitives.js
file.[Assigned to @gabrieldonadel] Note: This task depends on Extract the functionCommit ea9e78dtranslateArrayTypeAnnotation
Extract the content of thecase Array
andcase ReadOnlyArray
(Flow, Typescript) into anemitArrayType
function in theparsers-primitives.js
file.[Assigned to @Pranav-yadav] Extract the content of theCommit 5744b21tryParse
(Flow, TypeScript)lambda into a properparseObjectProperty
function into theparsers-commons.js
file.[Assigned to @AntoineDoubovetzky] Extract theCommit 8c69b6cUnsupportedFunctionParamTypeAnnotationParserError
(Flow, Typescript) 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.[Assigned to @gabrieldonadel] This task is more complex than the others and it depends on Extract theCommit 62244d4UnsupportedFunctionParamTypeAnnotationParserError
Extract thetranslateFunctionTypeAnnotation
(Flow, TypeScript)into a common function in theparsers-primitives.js
file. This function extracts some information from the ASTs that have different structures for Flow and Typescript. Whenever there is such difference, create an helper function that takes thetypeAnnotation
and the language to make the decision. For example: in thefor
loop at the beginning of the function, the flow parser gets the list of parameters fromflowFunctionTypeAnnotation.params
while the typescript parser usestypescriptFunctionTypeAnnotation.parameters
. In this case, you'll have to create a functiongetTypeAnnotationParameters(typeAnnotation, language)
with a simple switch over the languages to return the array of parameters.[Assigned to @Marcoo09] This task depends on Extract theCommit 64ea7cetranslateFunctionTypeAnnotation
Move thetranslateFunctionTypeAnnotation
invocation (Flow, TypeScript) into theemitFunction
call so that thecase FuntionTypeAnnotation
results in a one-liner.[Assigned to @Pranav-yadav] This task depends on Extract theCommit fb37deatranslateFunctionTypeAnnotation
Extract thebuildPropertySchema
(Flow TypeScript) into theparsers-commons.js
file. It has to take the language parameter to extract the value and an additional callback for theresolveTypeAnnotation
function.[Codegen_buildModuleSchema - assign to @tarunrajput] Extract theCommit 3cd97e4buildModuleSchema
function (Flow, TypeScript)in theparsers-commons.js
function. The two functions are almost identical except for thefilter(property =>)
at the end of the function, which is different based on the language.[Assigned to @Pranav-yadav] Move theCommit 95e685aemitMixedTypeAnnotation
function to theparser-primitives.js
file.[Assigned to @AntoineDoubovetzky] Create a new functionCommit 8a847a3typeParameterInstantiation
in theparsers.js
file and add documentation to it. Implement it properly in theFlowParser.js
and in theTypeScriptParser.js
. Update the signature ofassertGenericTypeAnnotationHasExactlyOneTypeParameter
function to take theParser
instead of the language and use the new function in place of the ternary operator?:
.[Assigned to @youedd] Create a new functionCommit a7ae988remapUnionTypeAnnotationMemberNames
in theparser.js
file and add documentation to it. Implement it properly in theFlowParser.js
and in theTypeScriptParser.js
. Remove the functionremapUnionTypeAnnotationMemberNames
and update theemitUnionTypeAnnotation
signature to accept aParser
parameter instead of a language one. Use the new Parser function instead of the old one here.[Assigned to @gabrieldonadel] Create a getKeyName function in theCommit f849f49parser.js
file and document it. Implement it properly in theFlowParser.js
and in theTypeScriptParser.js
: it should contain theObjectTypeProperty
and theObjectTypeIndexer
for Flow and theTSObjectTypeProperty
and theTSObjectTypeIndexer
. Remove the oldgetKeyName
function and use the new one in the parser object wherever the other was used.[Assigned to @AntoineDoubovetzky] Update theCommit edc4ea0IncorrectlyParameterizedGenericParserError
error in theerror.js
file to accept aParser
instead of aParserType
parameter. Use thenameForGenericTypeAnnotation
method of the parser to extract thegenericName
and delete the ternary operator.[Assigned to @tarunrajput] Create aCommit e97fb46checkIfInvalidModule
function in theparser.js
file and document it. Implement this logic in theFlowParser.js
and this logic in theTypeScriptParser.js
. Refactor thethrowIfIncorrectModuleRegistryCallTypeParameterParserError
function to accept a Parser instead of a ParserType and use the newly created function instead of theif (language)
logic.[Codegen_functionTypeAnnotation - assigned to @gabrieldonadel] Define aCommit 43986e8functionTypeAnnotation
in theparser.js
file and document it. Implement this logic in theFlowParser.js
and this logic in theTypeScriptParser.js
. Refactor thethrowIfModuleTypeIsUnsupported
function to accept aParser
instead of aParserType
and use the newly created function instead of theif (language)
logic.[Codegen 74 assigned to @AntoineDoubovetzky] MoveCommit f23f7f4getTypes
functions fromutils.js
to specific Parsers. Right now we have two Parser classes that takes care of the language specific details and two utils files that contains similar logic. We would like to move everything under the Parsers classes for better OOP architecture and to encourage code-reuse.[Codegen 75 assigned to @gabrieldonadel] Create aCommit 5ff8895throwIfPartialWithMoreParameter
function in theerror-utils.js
and extract the error-emitting code from Flow and Typescript index files.[Codegen 76 - assigned to @tarunrajput ] Create aCommit 371e263throwIfPartialNotAnnotatingTypeParameter
function in theerror-utils.js
file and extract the error-emitting code from Flow and Typescript index files. Notice that the way in which theannotatedElement
is computed is different, therefore we should add anextractAnnotatedElement
function to the Flow and TypeScript parsers.[Codegen 77 - assigned to @MaeIg] Extract the functions to compute partial properties from theCommit a448c6dindex.js
file (Flow and TypeScript)in the Flow and TypeScript parsers.[Codegen 78 - Assigned to @Pranav-yadav] It depends on [Codegen 75][Codegen 76][Codegen 77] Extract the logic that emits Partial values in anCommit 2f25261emitPartial
function, which takes the Parsers as parameter.[Codegen 79 - Assigned to @Pranav-yadav] It depends on [Codegen 78] Extract the basicCommit 2f25261cases
logics (case Stringish
,case Int32
,case Double
, ...,case Partial
. Flow lines and TypeScript lines) into a functionemitCommonTypes
inparsers-primitives.js
. Make sure that thedefault
case returnsnull
. Call this function in thedefault:
case (Flow, TypeScript) of theindex.js
file: if the function return something, return that from thedefault
case; otherwise if theemitCommonTypes
returnsnull
, keep the currentdefault
implementation (throw the error).[Codegen 80 - assigned to @kyawthura-gg] It depends on [Codegen 79] Convert theCommit 4a15f90emitCommonTypes
implementation from a switch based implementation to a dictionary based one.[Codegen 81 - Assigned to @gabrieldonadel] It depends on [Codegen 80] Expand theCommit 66ae98eemitcCommonTypes
function adding the remaining basic types: lines for Flow and lines for Typescript: the way to do it is by using theflow
keys in the dictionary and by implementing aconvertKeywordToTypeannotation
function in the two parsers. The flow parser will return the same parameter it receives as input, the TypeScript parser will convert the TypeAnnotation to Keywords. For example,TSBooleanKeyword
will becomeBooleanTypeAnnotation
. Call theemitCommonTypes
in thedefault:
case: if it return something, use that as returned type. Otherwise, keep the current implementation which throws an error.[Codegen 82 - assigned to @kyawthura-gg] MoveCommit 85245afisModuleInterface
function (Flow, TypeScript) to the Flow and TypeScript parsers.[Codegen 83 - assigned to @Pranav-yadav] Create a functionCommit 1362820throwIfIncorrectModuleRegistryCallArgumnent
function in theerror-utils.js
file and factor together the code from Flow and TypeScript. Update the Parsers to return the right Literl type[Codegen 84 - assigned to @Pranav-yadav] It depends on [Codegen 83] export theCommit 05454faparseModuleName
anonymous function (Flow, TypeScript) in a commonparseModuleName
function in theparsers-commons.js
file.[Codegen 85 - assigned to @tarunrajput] TheCommit 8be9dbfparses/flow/components/schema.js
andparses/typescript/components/schema.js
are the same. Move theschema.js
from the one of the two folders to theparsers
common root. Delete the other. Update the references to use the shared file.[Codegen 86 - Assigned to @ken0nek] TheCommit 0212179buildPropSchema
function inparsers/typescript/components/props.js
andparsers/flow/components/props.js
is the same. move it inparser-commons
and use it in the origina files.[Codegen 87 - Assigned to @siddarthkay] Depends on [Codegen 86] Add theCommit fc927d1getProps
function to the Parsers abstract class and implement it in the Flow and TypeScript parsers: this is the reference implementation for Flow and TypeScript. Remove theprops.js
files afterward.[Codegen 88 - assigned to @tarunrajput] Move the Visitor.js file fromCommit d9f2cbeparsers/flow/Visitor.js
toparser-promitives.js
. Copy theTSInterfaceDeclaration(node: $FlowFixMe)
function and add it to the Visitor.js just copied. Remove theparsers/typescript/Visitor.js
. Make sure we use the same Visitor in both parsers. (We will end up with a Visitor that is the union of the two, being able to handle both Flow and TS. In this specific case, this trade-off make sense as it allows us to remove one file, several duplicated lines for a small price.)[Codegen 89 - Assigned to @MaeIg] Remove theCommit 26b22a6const language
variable fromflow/modules/index.js
and replace its usage withparser.language()
[Codegen 90 - Assigned to @MaeIg] Remove theCommit 26b22a6const language
variable fromtypescript/modules/index.js
and replace its usage withparser.language()
[Codegen 91 - Assigned to @yux-m] Extract the inner switch inCommit 94f505btypescript/modules/index.js
at line to parse thecase TSTypereference
(lines)into a functiontranslateTypeReferenceAnnotation()
(the goal is to try and get a simpler switch statement and to spot structural similiarities between the flow and typescript index.js files)[Codegen 92 - assigned to @kyawthura-gg] TheCommit 221aacdgetCommandOptions
function inparsers/typescript/components/options.js
andparsers/flow/components/options.js
is the same. move it inparser-commons
and use it in the original files. If the file twooptions.js
files are empty, delete them.[Codegen 93 - assigned to @tarunrajput] The221aacdgetOptions
function inparsers/typescript/components/options.js
andparsers/flow/components/options.js
is the same. move it inparser-commons
and use it in the original files. If the file twooptions.js
files are empty, delete them.[Codegen 94 - assigned to @siddarthkay] TheCommit c937162extendsForProp
function inparsers/typescript/components/extends.js
andparsers/flow/components/extend.js
is the same. Move it inparser-commons
and use it in the origina files.[Codegen 95 - assigned to @Pranav-yadav] Extract theCommit c0a46c696b7365a0b74fc4dbf41e83de24305d7fdefaultExports.forEach(statement =>
(Flow, TS) function inparser-commons
, so that it accept a Parser parameter to unify the behaviors between flow and typescript. The Parser object needs to be enriched with all the methods to extract the required information from the Node, if they are not there yet.[Codegen 96 - assigned to @AntoineDoubovetzky] Create aCommit 8fbcfcethrowIfConfigNotfound
in theerror-utils.js
file and extract the error code from Flow and TS[Codegen 97 - assigned to @AntoineDoubovetzky] Create aCommit 8fbcfcethrowIfMoreThanOneConfig
in theerror-utils.js
file and extract the error code from Flow and TS[Codegen 98 - assigned to @MaeIg] Extract theCommit 5ff01bcnamedExports.map(statement =>
(Flow, TS) function inparser-commons
, so that it accept a Parser parameter to unify the behaviors between flow and typescript. The Parser object needs to be enriched with all the methods to extract the required information from the Node, if they are not there yet.[Codegen 99 - assigned to @tarunrajput] Extract theCommit (347d6f8)[https://github.com/facebook/react-native/commit/347d6f8d899d7a8f5c901611923c9c09039acbdb]throwIfMoreThanOneCodegenNativecommands
error in theerror-utils.js
file and extract the error code from Flow and TS[Codegen 100 - assigned to @marcocaldera] Create aCommit 320e51fcreateComponentConfig
function in theparser-commons.js
file. It takes thefoundConfig
and thecommandTypeNames
as parameters and returns the component config object. Extract thereturn
statements (Flow TS) and use those implementations in that function.[Codegen 101 - assigned to @kyawthura-gg] The code ofCommit 969a8d0getCommandProperties
is almost identical in Flow and TS. 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.[Codegen 102 - assigned to @Pranav-yadav] Extract the code to compute theCommit efc6e14extendsProps
and theprops
properties in Flow in agetProps() -> {extendsProps, props}
function into the sameindex.js
file. This will help unifying thebuildComponentSchema
functions between Flow and TS so we can factor it out in a later step.[Codegen 103 - assigned to @gabrieldonadel] Extract the code to compute theCommit e962d43extendsProps
and theprops
properties in TypeScript in agetProps() -> {extendsProps, props}
function into the sameindex.js
file. This will help unifying thebuildComponentSchema
functions between Flow and TS so we can factor it out in a later step[Codegen 104 - Assigned to @siddarthkay] Add aCommit e09d585getResolvedTypeAnnotation
function to the Parser class. Implement that function in the FlowParser and TypeScriptParser, using the implementation found in theparsers/flow/utils.js
andparsers/typescript/utils.js
. Then, replace those lines using the new function.[Codegen 105 - Assigned to @tarunrajput] Add aCommit 0de4768typeAlias: string
property to the Parser class. Implement it in the Flow parser so that it returnsTypeAlias
and inthe TypeScriptParser so that it returns
TSTypeAliasDeclaration
. Replace thecase
in theswitch
in theparsers/flow/utils.js
andparsers/typescript/utils.js
with this prop.[Codegen 106 - Assigned to @tarunrajput] Add aCommit 91c60cbenumDeclaration: string
property to the Parser class. Implement it in the Flow parser so that it returnsEnumDeclaration
and in the TypeScriptParser so that it returnsTSEnumDeclaration
. Replace thecase
in theswitch
in theparsers/flow/utils.js
andparsers/typescript/utils.js
with this prop.[Codegen 107 - @Shubham1429] Add aCommit 9301c8finterfaceDeclaration: string
property to the Parser class. Implement it in the Flow parser so that it returnsInterfaceDeclaration
and in the TypeScriptParser so that it returnsTSInterfaceDeclaration
. Replace thecase
in theswitch
in theparsers/typescript/utils.js
with this prop.[Codegen 108 - Depends on 105, 106, 107 - Assigned to @tarunrajput] Move theCommit (8ffaede)[https://github.com/facebook/react-native/commit/8ffaede05a72973805f668e1dda41060ee054dc4]switch
construct fromparsers/typescript/utils.js
andparsers/flow/utils.js
to theparsers-commons.js
file, in ahandleGenericTypeAnnotation
function. Use that function in place of theswitch
.[Codegen 109 - assigned to @tarunrajput] Extract the typeAnnotation doesn't have a name error (Commit c65ab4dFlow
;TypeScript
) inthrowIfEventHasNoName
function which takes a typeAnnotation and a parser as parameters. Use it in place of the if in the above call sites.[Codegen 110 - Assigned to @kyawthura-gg ] Add a
Commit b5c01eenullLiteralTypeAnnotation: string
property into the Parser object and implement it in theFlowParser
(returningNullLiteralTypeAnnotation
) and in theTypeScriptParser
(returningTSNullKeyword
). Replace them in theparsers/flow/components/events.js
andparsers/typescript/components/events.js
.[Codegen 111 - assigned to @Shubham1429] Add anCommit cf8184dundefinedLiteralTypeAnnotation: string
property into the Parser object and implement it in theFlowParser
(returningVoidLiteralTypeAnnotation
) and in theTypeScriptPArser
(returningTSUndefinedKeyword
). Replace them in andparsers/typescript/components/events.js
.[Codegen 112 - Depends on 110 and 111 - assigned to @kyawthura-gg] - Extract the content of theCommit ccd191d79if
branches that handle the EventHandlers (Flow, TypeScript) into ahandleEventHandler
function inparsers-commons.js
. This will take a name, a typeAnnotation, a parser and afindEventArgumentsAndType
function as parameters. Use the switch based approach from TypeScript.[Codegen 113 - assigned to @Shubham1429] Add a functionCommit ec66f2eisOptionalProperty(property)
in the Parser object and implement it in FlowParser and TypeScriptParser, using the implementation you can find in theparsers/flow/components/events.js
andparsers/typescript/components/events.js
. Use the parsers in thebuildPropertiesForEvent
.[Codegen 114 - Assigned to @MaeIg] Add a functionCommit (663a018)[https://github.com/facebook/react-native/commit/663a0187094b12d423742e65523c20e778925973]getTypeAnnotationFromProperty(property)
in the Parser object and implement it in FlowParser and TypeScriptParser, using the implementation you can find in theparsers/flow/components/events.js
andparsers/typescript/components/events.js
. Use the parsers in thebuildPropertiesForEvent
.[Codegen 116 - assigned to @siddarthkay] Extract theCommit d46f92cgetEventArgument
function fromFlow
andTypeScript
in agetEventArgument
function inparsers-commons.js
.[Codegen 117 - assigned to @AntoineDoubovetzky] Extract the code that throws if argumentProps are null in aCommit f05252athrowIfArgumentPropsAreNull
function in theerror-utils.js
file. Use it in theflow/components/events.js
and in thetypescript/components/event.js
files[Codegen 118 - Assigned to @tarunrajput] Extract the code that throws if argumentProps are null in aCommit 8494707throwIfBubblingTypeisNull
function in theerror-utils.js
file. Use it in theflow/components/events.js
and in thetypescript/components/event.js
files[Codegen 119 - Depends on 117, 118 - Assigned to @siddarthkay] Extract the content of theCommit 1d87279if (bubblingType && argumentProps) {
fromFlow
and the content of theelse
branch fromTypeScript
in a 'emitBuildEventSchema' function inparsers-commons
. Use the new function in the call site. Refactor the callsite so that there are noif-else
as, at this point, we know thatbubblingType
andargumentProps
are not null.[Codegen 120 - Assigned to @Pranav-yadav] Extract theCommit e240879findComponentConfig
from Flow and TypeScript from theindex.js
's files to theparser-commons.js
file.[Codegen 121 - Depends on Codegen 107 - Assigned to @Shubham1429] Extract the code that checks whetherCommit 66f4a91typeAlias.type
is anInterfaceDeclaration
(Flow, TypeScript) into athrowIfTypeAliasIsNotInteface
error. Create this new function in theerror-utils.js
file.[Codegen 122 - Depends on 121 - Assigned to @Shubham1429] Extract theCommit (34c1923)[https://github.com/facebook/react-native/commit/34c19232d36190650a7d2d1596ac4f9d4a725777]buildCommandProperties
function (Flow, TypeScript) from theindex.js
's files to theparsers-commons.js
file.[Codegen 123 - Assigned to @frankcalise] Create a functionCommit 66f4a91emitBoolProp(name: string, optional: boolean)
inparser-primitives.js
. Factor out the code from Flow and TypeScript into that function. Use that function in the original call site.[Codegen 124 - Assigned to @cloudpresser] Create a functionCommit 7062398emitStringProp(name: string, optional: boolean)
inparser-primitives.js
. Factor out the code from Flow and TypeScript into that function. Use that function in the original call site.[Codegen 125 - Assigend to @ahmadao2214] Create a functionCommit (52154e5)[https://github.com/facebook/react-native/commit/52154e54a29f0fc0e5dd73102bd384298a3ce460]emitInt32Prop(name: string, optional: boolean)
inparser-primitives.js
. Factor out the code from Flow and TypeScript into that function. Use that function in the original call site.[Codegen 126 - Assigned to @rota-rossi] Create a functionCommit 8ca085cemitDoubleProp(name: string, optional: boolean)
inparser-primitives.js
. Factor out the code from Flow and TypeScript into that function. Use that function in the original call site.[Codegen 127 - Assigned to @foestauf] Create a functionCommit 1a1e399emitFloatProp(name: string, optional: boolean)
inparser-primitives.js
. Factor out the code from Flow and TypeScript into that function. Use that function in the original call site.[Codegen 128 - Assigned to @gabrieldonadel] Create aCommit b5f5221getObjectProperties(typeAnnotation)
function inParser.js
which returns the properties of an object represented by a type annotation. Use this code for Flow and this code for TypeScript. Useparser.getObjectProperties(typeAnnotation)
instead of the language specific to map the object properties[Codegen 129 - Depends on 128 - Assigned to @tarunrajput] Create a functionCommit 202b965emitObjectProp(name: string, optional: boolean)
inparser-primitives.js
. Factor out the code from Flow and TypeScript into that function. Use that function in the original call site.[Codegen 130 - assigned to @Zwem ] Create aCommit 6d5be26getLiteralValue(option)
function inParser.js
which returns the literal value of an union represented, given an option. Use this code for Flow and this code for TypeScript. Useparser.getObjectProperties(typeAnnotation)
instead of the language specific to map the object properties[Codegen 131 - Depends on 130 - assigned to @Zwem] Create a function5eaf28bemitUnionProp(name: string, optional: boolean)
inparser-primitives.js
. Factor out the code from Flow and TypeScript into that function. Use that function in the original call site.[Codegen 132 - Assigned to @siddarthkay] Create a functionCommit (a497882)[https://github.com/facebook/react-native/commit/a4978823841177ff70959e28ed8343b78fb14c20]emitMixedProp(name: string, optional: boolean)
inparser-primitives.js
. Factor out the code from Flow and TypeScript into that function. Use that function in the original call site.[Codegen 133 - Assigned to @Randall71] Create anCommit 67eb494extractTypeFromTypeAnnotation(typeAnnotation)
function in the Parser base class. Implement it using this code for Flow and this code for TypeScript. Replace the invocation of that function with the one from the parser[Codegen 134 - Assigned to @cloudpresser] Create a functionCommit e22d1a1getTypeAnnotationName(typeAnnotation)
in the Parser base class. Implement it using this code for Flow and this code for Typescript. Replace the callsites with the new function.[Codegen 135 - assigned to @siddarthkay] Create a function8bcfc49getPaperTopLevelNameDeprecated(typeAnnotation)
in the Parser base class. Implement it using this code for Flow and this code for Typescript. Replace the callsites with the new function.[Codegen 137 - Assigned to @tarunrajput] ExtractCommit 942bd61buildPropertiesForEvent
intoparsers-commons.js
file. Use the code from either Flow or TypeScript which now should be equal. Delete the original ones and use the newly created method instead of those.[Codegen 138 - Assigned to @siddarthkay] Add aCommit e73c00f576getProperties
function to the Parser base class. Move the Flow code to the FlowParser and the TypeScript code to the TypeScriptParser. Use theparser.getProperties
function in place of the original one.[Codegen 139 - Assigned to @branaust] Move theCommit a108dcbverifyProprsNotAlreadyDefined
functions from Flow and [from TypeScript(https://github.com/facebook/react-native/blob/d8ced6f8953cd896471983714e722caf50783960/packages/react-native-codegen/src/parsers/typescript/components/componentsUtils.js#LL486-L495)] to theparsers-commons.js
file. Use the new function in place of the others.The text was updated successfully, but these errors were encountered: