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 numberDiff line numberDiff line change
Expand Up@@ -49,7 +49,7 @@ const {emitUnion} = require('../parsers-primitives');
const {UnsupportedUnionTypeAnnotationParserError} = require('../errors');
const {FlowParser} = require('../flow/parser');
const {TypeScriptParser} = require('../typescript/parser');
const {getPropertyType} = require('../flow/components/events');
const {extractArrayElementType} = require('../flow/components/events');

const parser = new MockedParser();
const flowParser = new FlowParser();
Expand DownExpand Up@@ -1679,6 +1679,10 @@ describe('emitObjectProp', () => {
describe('when property is optional', () => {
it('returns optional Object Prop', () => {
const typeAnnotation = {
type: 'GenericTypeAnnotation',
id: {
name: 'ObjectTypeAnnotation',
},
properties: [
{
key: {
Expand All@@ -1699,7 +1703,7 @@ describe('emitObjectProp', () => {
true,
flowParser,
typeAnnotation,
getPropertyType,
extractArrayElementType,
);
const expected = {
name: 'someProp',
Expand All@@ -1725,6 +1729,10 @@ describe('emitObjectProp', () => {
describe('when property is required', () => {
it('returns required Object Prop', () => {
const typeAnnotation = {
type: 'GenericTypeAnnotation',
id: {
name: 'ObjectTypeAnnotation',
},
properties: [
{
key: {
Expand All@@ -1745,7 +1753,7 @@ describe('emitObjectProp', () => {
false,
flowParser,
typeAnnotation,
getPropertyType,
extractArrayElementType,
);
const expected = {
name: 'someProp',
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,7 +70,7 @@ function getPropertyType(
optional,
parser,
typeAnnotation,
getPropertyType,
extractArrayElementType,
);
case 'UnionTypeAnnotation':
return {
Expand DownExpand Up@@ -311,5 +311,5 @@ function getEvents(

module.exports = {
getEvents,
getPropertyType,
extractArrayElementType,
};
17 changes: 4 additions & 13 deletions packages/react-native-codegen/src/parsers/parsers-primitives.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -60,7 +60,6 @@ const {
wrapNullable,
unwrapNullable,
translateFunctionTypeAnnotation,
buildPropertiesForEvent,
} = require('./parsers-commons');

const {isModuleRegistryCall} = require('./utils');
Expand DownExpand Up@@ -663,24 +662,16 @@ function emitObjectProp(
optional: boolean,
parser: Parser,
typeAnnotation: $FlowFixMe,
getPropertyType: (
name: $FlowFixMe,
optional: boolean,
extractArrayElementType: (
typeAnnotation: $FlowFixMe,
name: string,
parser: Parser,
) => NamedShape<EventTypeAnnotation>,
) => EventTypeAnnotation,
): NamedShape<EventTypeAnnotation> {
return {
name,
optional,
typeAnnotation: {
type: 'ObjectTypeAnnotation',
properties: parser
.getObjectProperties(typeAnnotation)
.map(member =>
buildPropertiesForEvent(member, parser, getPropertyType),
),
},
typeAnnotation: extractArrayElementType(typeAnnotation, name, parser),
};
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,10 +50,7 @@ function getPropertyType(
const topLevelType = parseTopLevelType(annotation);
const typeAnnotation = topLevelType.type;
const optional = optionalProperty || topLevelType.optional;
const type =
typeAnnotation.type === 'TSTypeReference'
? typeAnnotation.typeName.name
: typeAnnotation.type;
const type = parser.extractTypeFromTypeAnnotation(typeAnnotation);

switch (type) {
case 'TSBooleanKeyword':
Expand All@@ -72,7 +69,7 @@ function getPropertyType(
optional,
parser,
typeAnnotation,
getPropertyType,
extractArrayElementType,
);
case 'TSUnionType':
return {
Expand All@@ -92,7 +89,6 @@ function getPropertyType(
typeAnnotation: extractArrayElementType(typeAnnotation, name, parser),
};
default:
(type: empty);
throw new Error(`Unable to determine event type for "${name}": ${type}`);
}
}
Expand DownExpand Up@@ -314,4 +310,5 @@ function getEvents(

module.exports = {
getEvents,
extractArrayElementType,
};