Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const {
throwIfEventHasNoName,
throwIfBubblingTypeIsNull,
} = require('../../error-utils');
const {getEventArgument} = require('../../parsers-commons');

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

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
function getEventArgument(argumentProps, name: $FlowFixMe) {
return {
type: 'ObjectTypeAnnotation',
properties: argumentProps.map(buildPropertiesForEvent),
};
}

function buildEventSchema(
types: TypeMap,
property: EventTypeAST,
Expand Down Expand Up @@ -307,7 +299,7 @@ function buildEventSchema(
paperTopLevelNameDeprecated,
typeAnnotation: {
type: 'EventTypeAnnotation',
argument: getEventArgument(argumentProps, name),
argument: getEventArgument(argumentProps, buildPropertiesForEvent),
},
};
}
Expand All @@ -324,7 +316,7 @@ function buildEventSchema(
bubblingType,
typeAnnotation: {
type: 'EventTypeAnnotation',
argument: getEventArgument(argumentProps, name),
argument: getEventArgument(argumentProps, buildPropertiesForEvent),
},
};
}
Expand Down
17 changes: 17 additions & 0 deletions packages/react-native-codegen/src/parsers/parsers-commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import type {
SchemaType,
NativeModuleEnumMap,
OptionsShape,
EventTypeAnnotation,
ObjectTypeAnnotation,
} from '../CodegenSchema.js';

import type {Parser} from './parser';
Expand Down Expand Up @@ -852,6 +854,20 @@ function extendsForProp(
}
}

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
function getEventArgument(
argumentProps: PropAST,
buildPropertiesForEvent: (
property: PropAST,
) => NamedShape<EventTypeAnnotation>,
): ObjectTypeAnnotation<EventTypeAnnotation> {
return {
type: 'ObjectTypeAnnotation',
properties: argumentProps.map(buildPropertiesForEvent),
};
}

module.exports = {
wrapModuleSchema,
unwrapNullable,
Expand All @@ -872,4 +888,5 @@ module.exports = {
getOptions,
getCommandTypeNameAndOptionsExpression,
extendsForProp,
getEventArgument,
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const {
throwIfEventHasNoName,
throwIfBubblingTypeIsNull,
} = require('../../error-utils');

const {getEventArgument} = require('../../parsers-commons');
function getPropertyType(
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
Expand Down Expand Up @@ -270,15 +270,6 @@ function buildPropertiesForEvent(property): NamedShape<EventTypeAnnotation> {
return getPropertyType(name, optional, typeAnnotation);
}

/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
function getEventArgument(argumentProps, name: $FlowFixMe) {
return {
type: 'ObjectTypeAnnotation',
properties: argumentProps.map(buildPropertiesForEvent),
};
}

// $FlowFixMe[unclear-type] TODO(T108222691): Use flow-types for @babel/parser
type EventTypeAST = Object;

Expand Down Expand Up @@ -312,7 +303,7 @@ function buildEventSchema(
paperTopLevelNameDeprecated,
typeAnnotation: {
type: 'EventTypeAnnotation',
argument: getEventArgument(argumentProps, name),
argument: getEventArgument(argumentProps, buildPropertiesForEvent),
},
};
}
Expand All @@ -323,7 +314,7 @@ function buildEventSchema(
bubblingType,
typeAnnotation: {
type: 'EventTypeAnnotation',
argument: getEventArgument(argumentProps, name),
argument: getEventArgument(argumentProps, buildPropertiesForEvent),
},
};
}
Expand Down