Skip to content

Commit f6cf9f8

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 9f496e2 commit f6cf9f8

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
@@ -185,15 +186,6 @@ function buildPropertiesForEvent(property): NamedShape<EventTypeAnnotation> {
185186
return getPropertyType(name, optional, typeAnnotation);
186187
}
187188

188-
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
189-
* LTI update could not be added via codemod */
190-
function getEventArgument(argumentProps, name: $FlowFixMe) {
191-
return {
192-
type: 'ObjectTypeAnnotation',
193-
properties: argumentProps.map(buildPropertiesForEvent),
194-
};
195-
}
196-
197189
function buildEventSchema(
198190
types: TypeMap,
199191
property: EventTypeAST,
@@ -228,7 +220,7 @@ function buildEventSchema(
228220
paperTopLevelNameDeprecated,
229221
typeAnnotation: {
230222
type: 'EventTypeAnnotation',
231-
argument: getEventArgument(argumentProps, name),
223+
argument: getEventArgument(argumentProps, buildPropertiesForEvent),
232224
},
233225
};
234226
}
@@ -239,7 +231,7 @@ function buildEventSchema(
239231
bubblingType,
240232
typeAnnotation: {
241233
type: 'EventTypeAnnotation',
242-
argument: getEventArgument(argumentProps, name),
234+
argument: getEventArgument(argumentProps, buildPropertiesForEvent),
243235
},
244236
};
245237
}

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 */
@@ -206,15 +206,6 @@ function buildPropertiesForEvent(property): NamedShape<EventTypeAnnotation> {
206206
return getPropertyType(name, optional, typeAnnotation);
207207
}
208208

209-
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
210-
* LTI update could not be added via codemod */
211-
function getEventArgument(argumentProps, name: $FlowFixMe) {
212-
return {
213-
type: 'ObjectTypeAnnotation',
214-
properties: argumentProps.map(buildPropertiesForEvent),
215-
};
216-
}
217-
218209
// $FlowFixMe[unclear-type] TODO(T108222691): Use flow-types for @babel/parser
219210
type EventTypeAST = Object;
220211

@@ -248,7 +239,7 @@ function buildEventSchema(
248239
paperTopLevelNameDeprecated,
249240
typeAnnotation: {
250241
type: 'EventTypeAnnotation',
251-
argument: getEventArgument(argumentProps, name),
242+
argument: getEventArgument(argumentProps, buildPropertiesForEvent),
252243
},
253244
};
254245
}
@@ -259,7 +250,7 @@ function buildEventSchema(
259250
bubblingType,
260251
typeAnnotation: {
261252
type: 'EventTypeAnnotation',
262-
argument: getEventArgument(argumentProps, name),
253+
argument: getEventArgument(argumentProps, buildPropertiesForEvent),
263254
},
264255
};
265256
}

0 commit comments

Comments
 (0)