Skip to content

Commit f9119a8

Browse files
committed
move getEventArgument fn to parsers-commons.js
Revert "move `getEventArgument` fn to `parsers-commons.js`" This reverts commit ce660bd. Address feedback use EventTypeAnnotation instead of defining type
1 parent 4fd8f40 commit f9119a8

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

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

Lines changed: 2 additions & 10 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
}

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)