File tree Expand file tree Collapse file tree 4 files changed +53
-16
lines changed
packages/react-native-codegen/src/parsers Expand file tree Collapse file tree 4 files changed +53
-16
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ const {
2424 emitDouble,
2525 emitDoubleProp,
2626 emitFloat,
27+ emitFloatProp,
2728 emitNumber,
2829 emitInt32,
2930 emitGenericObject,
@@ -711,6 +712,38 @@ describe('emitFloat', () => {
711712 } ) ;
712713} ) ;
713714
715+ describe ( 'emitFloatProp' , ( ) => {
716+ describe ( 'when optional is true' , ( ) => {
717+ it ( 'returns optional FloatTypeAnnotation' , ( ) => {
718+ const result = emitFloatProp ( 'myProp' , true ) ;
719+ const expected = {
720+ name : 'myProp' ,
721+ optional : true ,
722+ typeAnnotation : {
723+ type : 'FloatTypeAnnotation' ,
724+ } ,
725+ } ;
726+
727+ expect ( result ) . toEqual ( expected ) ;
728+ } ) ;
729+ } ) ;
730+
731+ describe ( 'when optional is false' , ( ) => {
732+ it ( 'returns required FloatTypeAnnotation' , ( ) => {
733+ const result = emitFloatProp ( 'myProp' , false ) ;
734+ const expected = {
735+ name : 'myProp' ,
736+ optional : false ,
737+ typeAnnotation : {
738+ type : 'FloatTypeAnnotation' ,
739+ } ,
740+ } ;
741+
742+ expect ( result ) . toEqual ( expected ) ;
743+ } ) ;
744+ } ) ;
745+ } ) ;
746+
714747describe ( 'emitMixed' , ( ) => {
715748 describe ( 'when nullable is true' , ( ) => {
716749 it ( 'returns nullable type annotation' , ( ) => {
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ const {getEventArgument} = require('../../parsers-commons');
2626const {
2727 emitBoolProp,
2828 emitDoubleProp,
29+ emitFloatProp,
2930 emitStringProp,
3031} = require ( '../../parsers-primitives' ) ;
3132
@@ -55,13 +56,7 @@ function getPropertyType(
5556 case 'Double' :
5657 return emitDoubleProp ( name , optional ) ;
5758 case 'Float' :
58- return {
59- name,
60- optional,
61- typeAnnotation : {
62- type : 'FloatTypeAnnotation' ,
63- } ,
64- } ;
59+ return emitFloatProp ( name , optional ) ;
6560 case '$ReadOnly' :
6661 return getPropertyType (
6762 name ,
Original file line number Diff line number Diff line change @@ -14,7 +14,9 @@ import type {
1414 Nullable ,
1515 BooleanTypeAnnotation ,
1616 DoubleTypeAnnotation ,
17+ EventTypeAnnotation ,
1718 Int32TypeAnnotation ,
19+ NamedShape ,
1820 NativeModuleAliasMap ,
1921 NativeModuleEnumMap ,
2022 NativeModuleBaseTypeAnnotation ,
@@ -33,8 +35,6 @@ import type {
3335 VoidTypeAnnotation ,
3436 NativeModuleObjectTypeAnnotation ,
3537 NativeModuleEnumDeclaration ,
36- NamedShape ,
37- EventTypeAnnotation ,
3838} from '../CodegenSchema' ;
3939import type { Parser } from './parser' ;
4040import type {
@@ -365,6 +365,19 @@ function emitFloat(
365365 } ) ;
366366}
367367
368+ function emitFloatProp (
369+ name : string ,
370+ optional : boolean ,
371+ ) : NamedShape < EventTypeAnnotation > {
372+ return {
373+ name,
374+ optional,
375+ typeAnnotation : {
376+ type : 'FloatTypeAnnotation' ,
377+ } ,
378+ } ;
379+ }
380+
368381function emitUnion (
369382 nullable : boolean ,
370383 hasteModuleName : string ,
@@ -625,6 +638,7 @@ module.exports = {
625638 emitDouble,
626639 emitDoubleProp,
627640 emitFloat,
641+ emitFloatProp,
628642 emitFunction,
629643 emitInt32,
630644 emitNumber,
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ const {getEventArgument} = require('../../parsers-commons');
2828const {
2929 emitBoolProp,
3030 emitDoubleProp,
31+ emitFloatProp,
3132 emitStringProp,
3233} = require ( '../../parsers-primitives' ) ;
3334function getPropertyType (
@@ -64,13 +65,7 @@ function getPropertyType(
6465 case 'Double' :
6566 return emitDoubleProp ( name , optional ) ;
6667 case 'Float' :
67- return {
68- name,
69- optional,
70- typeAnnotation : {
71- type : 'FloatTypeAnnotation' ,
72- } ,
73- } ;
68+ return emitFloatProp ( name , optional ) ;
7469 case 'TSTypeLiteral' :
7570 return {
7671 name,
You can’t perform that action at this time.
0 commit comments