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 @@ -16,6 +16,7 @@ import type {UnionTypeAnnotationMemberType} from '../../CodegenSchema';
const {
emitArrayType,
emitBoolean,
emitBoolProp,
emitDouble,
emitFloat,
emitNumber,
Expand Down Expand Up @@ -829,7 +830,7 @@ describe('emitUnion', () => {
'ObjectTypeAnnotation',
];
describe('when nullable is true', () => {
it('throws an excpetion', () => {
it('throws an exception', () => {
const expected = new UnsupportedUnionTypeAnnotationParserError(
hasteModuleName,
typeAnnotation,
Expand All @@ -843,7 +844,7 @@ describe('emitUnion', () => {
});

describe('when nullable is false', () => {
it('throws an excpetion', () => {
it('throws an exception', () => {
const expected = new UnsupportedUnionTypeAnnotationParserError(
hasteModuleName,
typeAnnotation,
Expand Down Expand Up @@ -1042,7 +1043,7 @@ describe('emitUnion', () => {
'ObjectTypeAnnotation',
];
describe('when nullable is true', () => {
it('throws an excpetion', () => {
it('throws an exception', () => {
const expected = new UnsupportedUnionTypeAnnotationParserError(
hasteModuleName,
typeAnnotation,
Expand All @@ -1056,7 +1057,7 @@ describe('emitUnion', () => {
});

describe('when nullable is false', () => {
it('throws an excpetion', () => {
it('throws an exception', () => {
const expected = new UnsupportedUnionTypeAnnotationParserError(
hasteModuleName,
typeAnnotation,
Expand Down Expand Up @@ -1506,3 +1507,34 @@ describe('emitCommonTypes', () => {
});
});
});

describe('emitBoolProp', () => {
describe('when optional is true', () => {
it('returns optional type annotation', () => {
const result = emitBoolProp('someProp', true);
const expected = {
name: 'someProp',
optional: true,
typeAnnotation: {
type: 'BooleanTypeAnnotation',
},
};

expect(result).toEqual(expected);
});
});
describe('when optional is false', () => {
it('returns required type annotation', () => {
const result = emitBoolProp('someProp', false);
const expected = {
name: 'someProp',
optional: false,
typeAnnotation: {
type: 'BooleanTypeAnnotation',
},
};

expect(result).toEqual(expected);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ import type {
EventTypeAnnotation,
} from '../../../CodegenSchema.js';
import type {Parser} from '../../parser';

const {
throwIfEventHasNoName,
throwIfBubblingTypeIsNull,
throwIfArgumentPropsAreNull,
} = require('../../error-utils');
const {getEventArgument} = require('../../parsers-commons');
const {emitBoolProp} = require('../../parsers-primitives');

function getPropertyType(
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
Expand All @@ -35,13 +37,7 @@ function getPropertyType(

switch (type) {
case 'BooleanTypeAnnotation':
return {
name,
optional,
typeAnnotation: {
type: 'BooleanTypeAnnotation',
},
};
return emitBoolProp(name, optional);
case 'StringTypeAnnotation':
return {
name,
Expand Down
16 changes: 16 additions & 0 deletions packages/react-native-codegen/src/parsers/parsers-primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import type {
VoidTypeAnnotation,
NativeModuleObjectTypeAnnotation,
NativeModuleEnumDeclaration,
NamedShape,
EventTypeAnnotation,
} from '../CodegenSchema';
import type {Parser} from './parser';
import type {
Expand Down Expand Up @@ -577,9 +579,23 @@ function emitCommonTypes(
);
}

function emitBoolProp(
name: string,
optional: boolean,
): NamedShape<EventTypeAnnotation> {
return {
name,
optional,
typeAnnotation: {
type: 'BooleanTypeAnnotation',
},
};
}

module.exports = {
emitArrayType,
emitBoolean,
emitBoolProp,
emitDouble,
emitFloat,
emitFunction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const {
throwIfArgumentPropsAreNull,
} = require('../../error-utils');
const {getEventArgument} = require('../../parsers-commons');
const {emitBoolProp} = require('../../parsers-primitives');

function getPropertyType(
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
Expand All @@ -45,13 +47,7 @@ function getPropertyType(

switch (type) {
case 'TSBooleanKeyword':
return {
name,
optional,
typeAnnotation: {
type: 'BooleanTypeAnnotation',
},
};
return emitBoolProp(name, optional);
case 'TSStringKeyword':
return {
name,
Expand Down