File tree Expand file tree Collapse file tree 4 files changed +40
-7
lines changed
packages/react-native-codegen/src/parsers Expand file tree Collapse file tree 4 files changed +40
-7
lines changed Original file line number Diff line number Diff line change 1313
1414const {
1515 emitBoolean,
16+ emitDouble,
1617 emitNumber,
1718 emitInt32,
1819 emitRootTag,
19- } = require ( '../parsers-primitives' ) ;
20+ } = require ( '../parsers-primitives.js ' ) ;
2021
2122describe ( 'emitBoolean' , ( ) => {
2223 describe ( 'when nullable is true' , ( ) => {
@@ -121,3 +122,29 @@ describe('emitRootTag', () => {
121122 } ) ;
122123 } ) ;
123124} ) ;
125+
126+ describe ( 'emitDouble' , ( ) => {
127+ describe ( 'when nullable is true' , ( ) => {
128+ it ( 'returns nullable type annotation' , ( ) => {
129+ const result = emitDouble ( true ) ;
130+ const expected = {
131+ type : 'NullableTypeAnnotation' ,
132+ typeAnnotation : {
133+ type : 'DoubleTypeAnnotation' ,
134+ } ,
135+ } ;
136+
137+ expect ( result ) . toEqual ( expected ) ;
138+ } ) ;
139+ } ) ;
140+ describe ( 'when nullable is false' , ( ) => {
141+ it ( 'returns non nullable type annotation' , ( ) => {
142+ const result = emitDouble ( false ) ;
143+ const expected = {
144+ type : 'DoubleTypeAnnotation' ,
145+ } ;
146+
147+ expect ( result ) . toEqual ( expected ) ;
148+ } ) ;
149+ } ) ;
150+ } ) ;
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ const {
3535const { unwrapNullable, wrapNullable} = require ( '../../parsers-commons' ) ;
3636const {
3737 emitBoolean,
38+ emitDouble,
3839 emitNumber,
3940 emitInt32,
4041 emitRootTag,
@@ -204,9 +205,7 @@ function translateTypeAnnotation(
204205 return emitInt32 ( nullable ) ;
205206 }
206207 case 'Double': {
207- return wrapNullable ( nullable , {
208- type : 'DoubleTypeAnnotation' ,
209- } ) ;
208+ return emitDouble ( nullable ) ;
210209 }
211210 case 'Float': {
212211 return wrapNullable ( nullable , {
Original file line number Diff line number Diff line change 1212
1313import type {
1414 BooleanTypeAnnotation ,
15+ DoubleTypeAnnotation ,
1516 Int32TypeAnnotation ,
1617 NativeModuleNumberTypeAnnotation ,
1718 Nullable ,
@@ -47,8 +48,15 @@ function emitRootTag(nullable: boolean): Nullable<ReservedTypeAnnotation> {
4748 } ) ;
4849}
4950
51+ function emitDouble ( nullable : boolean ) : Nullable < DoubleTypeAnnotation > {
52+ return wrapNullable ( nullable , {
53+ type : 'DoubleTypeAnnotation' ,
54+ } ) ;
55+ }
56+
5057module . exports = {
5158 emitBoolean,
59+ emitDouble,
5260 emitInt32,
5361 emitNumber,
5462 emitRootTag,
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ const {
3535const { unwrapNullable, wrapNullable} = require ( '../../parsers-commons' ) ;
3636const {
3737 emitBoolean,
38+ emitDouble,
3839 emitNumber,
3940 emitInt32,
4041 emitRootTag,
@@ -238,9 +239,7 @@ function translateTypeAnnotation(
238239 return emitInt32 ( nullable ) ;
239240 }
240241 case 'Double ': {
241- return wrapNullable ( nullable , {
242- type : 'DoubleTypeAnnotation' ,
243- } ) ;
242+ return emitDouble ( nullable ) ;
244243 }
245244 case 'Float ': {
246245 return wrapNullable ( nullable , {
You can’t perform that action at this time.
0 commit comments