Skip to content

Commit d46f92c

Browse files
siddarthkayfacebook-github-bot
authored andcommitted
move getEventArgument function into parsers-commons.js (#37133)
Summary: [Codegen 116] This PR attempts to extract the logic of `getEventArgument` function from the following locations : - `parsers/flow/components/events.js` - `parsers/typescript/components/events.js` since they are the same and move the function to `parsers/parsers-commons.js` as requested on #34872 ## Changelog: [Internal] [Changed] - Move `getEventArgument` to parser-commons and update usages. Pull Request resolved: #37133 Test Plan: Run `yarn jest react-native-codegen` and ensure CI is green Reviewed By: christophpurrer Differential Revision: D45569128 Pulled By: cipolleschi fbshipit-source-id: 63a7619e5b4fca0157c62a359ac51831f4f15945
1 parent 74987b6 commit d46f92c

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

packages/react-native-codegen/src/parsers/flow/components/events.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const {
2020
throwIfEventHasNoName,
2121
throwIfBubblingTypeIsNull,
2222
} = require('../../error-utils');
23+
const {getEventArgument} = require('../../parsers-commons');
2324

2425
function getPropertyType(
2526
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
@@ -257,15 +258,6 @@ function buildPropertiesForEvent(property): NamedShape<EventTypeAnnotation> {
257258
return getPropertyType(name, optional, typeAnnotation);
258259
}
259260

260-
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
261-
* LTI update could not be added via codemod */
262-
function getEventArgument(argumentProps, name: $FlowFixMe) {
263-
return {
264-
type: 'ObjectTypeAnnotation',
265-
properties: argumentProps.map(buildPropertiesForEvent),
266-
};
267-
}
268-
269261
function buildEventSchema(
270262
types: TypeMap,
271263
property: EventTypeAST,
@@ -307,7 +299,7 @@ function buildEventSchema(
307299
paperTopLevelNameDeprecated,
308300
typeAnnotation: {
309301
type: 'EventTypeAnnotation',
310-
argument: getEventArgument(argumentProps, name),
302+
argument: getEventArgument(argumentProps, buildPropertiesForEvent),
311303
},
312304
};
313305
}
@@ -324,7 +316,7 @@ function buildEventSchema(
324316
bubblingType,
325317
typeAnnotation: {
326318
type: 'EventTypeAnnotation',
327-
argument: getEventArgument(argumentProps, name),
319+
argument: getEventArgument(argumentProps, buildPropertiesForEvent),
328320
},
329321
};
330322
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import type {
2323
SchemaType,
2424
NativeModuleEnumMap,
2525
OptionsShape,
26+
EventTypeAnnotation,
27+
ObjectTypeAnnotation,
2628
} from '../CodegenSchema.js';
2729

2830
import type {Parser} from './parser';
@@ -852,6 +854,20 @@ function extendsForProp(
852854
}
853855
}
854856

857+
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
858+
* LTI update could not be added via codemod */
859+
function getEventArgument(
860+
argumentProps: PropAST,
861+
buildPropertiesForEvent: (
862+
property: PropAST,
863+
) => NamedShape<EventTypeAnnotation>,
864+
): ObjectTypeAnnotation<EventTypeAnnotation> {
865+
return {
866+
type: 'ObjectTypeAnnotation',
867+
properties: argumentProps.map(buildPropertiesForEvent),
868+
};
869+
}
870+
855871
module.exports = {
856872
wrapModuleSchema,
857873
unwrapNullable,
@@ -872,4 +888,5 @@ module.exports = {
872888
getOptions,
873889
getCommandTypeNameAndOptionsExpression,
874890
extendsForProp,
891+
getEventArgument,
875892
};

packages/react-native-codegen/src/parsers/typescript/components/events.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const {
2323
throwIfEventHasNoName,
2424
throwIfBubblingTypeIsNull,
2525
} = require('../../error-utils');
26-
26+
const {getEventArgument} = require('../../parsers-commons');
2727
function getPropertyType(
2828
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
2929
* LTI update could not be added via codemod */
@@ -270,15 +270,6 @@ function buildPropertiesForEvent(property): NamedShape<EventTypeAnnotation> {
270270
return getPropertyType(name, optional, typeAnnotation);
271271
}
272272

273-
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
274-
* LTI update could not be added via codemod */
275-
function getEventArgument(argumentProps, name: $FlowFixMe) {
276-
return {
277-
type: 'ObjectTypeAnnotation',
278-
properties: argumentProps.map(buildPropertiesForEvent),
279-
};
280-
}
281-
282273
// $FlowFixMe[unclear-type] TODO(T108222691): Use flow-types for @babel/parser
283274
type EventTypeAST = Object;
284275

@@ -312,7 +303,7 @@ function buildEventSchema(
312303
paperTopLevelNameDeprecated,
313304
typeAnnotation: {
314305
type: 'EventTypeAnnotation',
315-
argument: getEventArgument(argumentProps, name),
306+
argument: getEventArgument(argumentProps, buildPropertiesForEvent),
316307
},
317308
};
318309
}
@@ -323,7 +314,7 @@ function buildEventSchema(
323314
bubblingType,
324315
typeAnnotation: {
325316
type: 'EventTypeAnnotation',
326-
argument: getEventArgument(argumentProps, name),
317+
argument: getEventArgument(argumentProps, buildPropertiesForEvent),
327318
},
328319
};
329320
}

0 commit comments

Comments
 (0)