Skip to content

Commit c403cd4

Browse files
mohitcharkhafacebook-github-bot
authored andcommitted
Extracted content of the case FunctionTypeAnnotation into emitFunction in parsers-primitives file (#34950)
Summary: This PR is part of #34872 This PR extracts the content of the case `FunctionTypeAnnotation` into a single `emitFunction` function inside the parsers-primitives.js file and uses it in both Flow and TypeScript 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 content of the case `FunctionTypeAnnotation` into a single `emitFunction` function Pull Request resolved: #34950 Test Plan: Run yarn jest react-native-codegen and ensure CI is green <img width="984" alt="Screenshot 2022-10-12 at 11 18 54 AM" src="https://user-images.githubusercontent.com/86604753/195260414-136f918f-e4b7-4fcf-b0b9-9142872f3cf9.png"> Reviewed By: christophpurrer Differential Revision: D40296823 Pulled By: cipolleschi fbshipit-source-id: 3cac407d260481bd6ae7c3e46642e4c16bba3376
1 parent 1eaa092 commit c403cd4

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

packages/react-native-codegen/src/parsers/flow/modules/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const {
4141
const {
4242
emitBoolean,
4343
emitDouble,
44+
emitFunction,
4445
emitNumber,
4546
emitInt32,
4647
emitObject,
@@ -372,17 +373,16 @@ function translateTypeAnnotation(
372373
});
373374
}
374375
case 'FunctionTypeAnnotation': {
375-
return wrapNullable(
376-
nullable,
376+
const translateFunctionTypeAnnotationValue: NativeModuleFunctionTypeAnnotation =
377377
translateFunctionTypeAnnotation(
378378
hasteModuleName,
379379
typeAnnotation,
380380
types,
381381
aliasMap,
382382
tryParse,
383383
cxxOnly,
384-
),
385-
);
384+
);
385+
return emitFunction(nullable, translateFunctionTypeAnnotationValue);
386386
}
387387
case 'UnionTypeAnnotation': {
388388
if (cxxOnly) {

packages/react-native-codegen/src/parsers/parsers-primitives.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
Nullable,
1515
NativeModuleAliasMap,
1616
NativeModuleBaseTypeAnnotation,
17+
NativeModuleFunctionTypeAnnotation,
1718
NativeModuleTypeAliasTypeAnnotation,
1819
NativeModuleNumberTypeAnnotation,
1920
BooleanTypeAnnotation,
@@ -23,8 +24,8 @@ import type {
2324
ReservedTypeAnnotation,
2425
ObjectTypeAnnotation,
2526
NativeModulePromiseTypeAnnotation,
26-
VoidTypeAnnotation,
2727
StringTypeAnnotation,
28+
VoidTypeAnnotation,
2829
} from '../CodegenSchema';
2930
import type {ParserType} from './errors';
3031
import type {TypeAliasResolutionStatus} from './utils';
@@ -78,6 +79,12 @@ function emitStringish(nullable: boolean): Nullable<StringTypeAnnotation> {
7879
type: 'StringTypeAnnotation',
7980
});
8081
}
82+
function emitFunction(
83+
nullable: boolean,
84+
translateFunctionTypeAnnotationValue: NativeModuleFunctionTypeAnnotation,
85+
): Nullable<NativeModuleFunctionTypeAnnotation> {
86+
return wrapNullable(nullable, translateFunctionTypeAnnotationValue);
87+
}
8188

8289
function typeAliasResolution(
8390
typeAliasResolutionStatus: TypeAliasResolutionStatus,
@@ -161,12 +168,13 @@ function emitObject(
161168
module.exports = {
162169
emitBoolean,
163170
emitDouble,
171+
emitFunction,
164172
emitInt32,
165173
emitNumber,
166174
emitObject,
167175
emitPromise,
168176
emitRootTag,
169-
emitVoid,
170177
emitStringish,
178+
emitVoid,
171179
typeAliasResolution,
172180
};

packages/react-native-codegen/src/parsers/typescript/modules/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const {
4141
const {
4242
emitBoolean,
4343
emitDouble,
44+
emitFunction,
4445
emitNumber,
4546
emitInt32,
4647
emitObject,
@@ -387,17 +388,17 @@ function translateTypeAnnotation(
387388
});
388389
}
389390
case 'TSFunctionType': {
390-
return wrapNullable(
391-
nullable,
391+
const translateFunctionTypeAnnotationValue: NativeModuleFunctionTypeAnnotation =
392392
translateFunctionTypeAnnotation(
393393
hasteModuleName,
394394
typeAnnotation,
395395
types,
396396
aliasMap,
397397
tryParse,
398398
cxxOnly,
399-
),
400-
);
399+
);
400+
401+
return emitFunction(nullable, translateFunctionTypeAnnotationValue);
401402
}
402403
case 'TSUnionType': {
403404
if (cxxOnly) {

0 commit comments

Comments
 (0)