Create a function emitDoubleProp (#37515)

Summary:
> Create a function emitDoubleProp(name: string, optional: boolean) in parser-primitives.js. Factor out the code from [Flow](https://github.com/facebook/react-native/blob/d8ced6f8953cd896471983714e722caf50783960/packages/react-native-codegen/src/parsers/flow/components/events.js#L61-L67) and [TypeScript](https://github.com/facebook/react-native/blob/d8ced6f8953cd896471983714e722caf50783960/packages/react-native-codegen/src/parsers/typescript/components/events.js#L71-L77) into that function. Use that function in the original call site.

bypass-github-export-checks

## Changelog:

[INTERNAL][ADDED] - emitDoubleProp in parser primitves

Pull Request resolved: https://github.com/facebook/react-native/pull/37515

Test Plan: yarn jest packages/react-native-codegen

Reviewed By: cortinico

Differential Revision: D46149450

Pulled By: cipolleschi

fbshipit-source-id: 78381214a79c33d975dff490599d510e8001254e
This commit is contained in:
Leonardo Rota-Rossi authored and Facebook GitHub Bot committed 2023-05-25 02:59:23 -07:00
1 parent 706239814e
commit 8ca085c09c
4 files changed
+61 -18

No files matched your search

@@ -11,13 +11,18 @@
'use-strict';
import type {UnionTypeAnnotationMemberType} from '../../CodegenSchema';
import type {
DoubleTypeAnnotation,
NamedShape,
UnionTypeAnnotationMemberType,
} from '../../CodegenSchema';
const {
emitArrayType,
emitBoolean,
emitBoolProp,
emitDouble,
emitDoubleProp,
emitFloat,
emitNumber,
emitInt32,
@@ -262,6 +267,35 @@ describe('emitDouble', () => {
});
});
describe('emitDoubleProp', () => {
describe('when optional is true', () => {
it('returns optional type annotation', () => {
const result = emitDoubleProp('Foo', true);
const expected: NamedShape<DoubleTypeAnnotation> = {
name: 'Foo',
optional: true,
typeAnnotation: {
type: 'DoubleTypeAnnotation',
},
};
expect(result).toEqual(expected);
});
});
describe('when optional is false', () => {
it('returns required type annotation', () => {
const result = emitDoubleProp('Foo', false);
const expected: NamedShape<DoubleTypeAnnotation> = {
name: 'Foo',
optional: false,
typeAnnotation: {
type: 'DoubleTypeAnnotation',
},
};
expect(result).toEqual(expected);
});
});
});
describe('emitVoid', () => {
describe('when nullable is true', () => {
it('returns nullable type annotation', () => {