File tree Expand file tree Collapse file tree 4 files changed +39
-6
lines changed
packages/react-native-codegen/src/parsers Expand file tree Collapse file tree 4 files changed +39
-6
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ const {
1919 emitObject,
2020 emitPromise,
2121 emitRootTag,
22+ emitVoid,
2223 typeAliasResolution,
2324} = require ( '../parsers-primitives.js' ) ;
2425
@@ -152,6 +153,32 @@ describe('emitDouble', () => {
152153 } ) ;
153154} ) ;
154155
156+ describe ( 'emitVoid' , ( ) => {
157+ describe ( 'when nullable is true' , ( ) => {
158+ it ( 'returns nullable type annotation' , ( ) => {
159+ const result = emitVoid ( true ) ;
160+ const expected = {
161+ type : 'NullableTypeAnnotation' ,
162+ typeAnnotation : {
163+ type : 'VoidTypeAnnotation' ,
164+ } ,
165+ } ;
166+
167+ expect ( result ) . toEqual ( expected ) ;
168+ } ) ;
169+ } ) ;
170+ describe ( 'when nullable is false' , ( ) => {
171+ it ( 'returns non nullable type annotation' , ( ) => {
172+ const result = emitVoid ( false ) ;
173+ const expected = {
174+ type : 'VoidTypeAnnotation' ,
175+ } ;
176+
177+ expect ( result ) . toEqual ( expected ) ;
178+ } ) ;
179+ } ) ;
180+ } ) ;
181+
155182describe ( 'typeAliasResolution' , ( ) => {
156183 const objectTypeAnnotation = {
157184 type : 'ObjectTypeAnnotation' ,
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ const {
4545 emitObject,
4646 emitPromise,
4747 emitRootTag,
48+ emitVoid,
4849 typeAliasResolution,
4950} = require ( '../../parsers-primitives' ) ;
5051const {
@@ -345,9 +346,7 @@ function translateTypeAnnotation(
345346 return emitNumber ( nullable ) ;
346347 }
347348 case 'VoidTypeAnnotation': {
348- return wrapNullable ( nullable , {
349- type : 'VoidTypeAnnotation' ,
350- } ) ;
349+ return emitVoid ( nullable ) ;
351350 }
352351 case 'StringTypeAnnotation': {
353352 return wrapNullable ( nullable , {
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import type {
2323 ReservedTypeAnnotation ,
2424 ObjectTypeAnnotation ,
2525 NativeModulePromiseTypeAnnotation ,
26+ VoidTypeAnnotation ,
2627} from '../CodegenSchema' ;
2728import type { ParserType } from './errors' ;
2829import type { TypeAliasResolutionStatus } from './utils' ;
@@ -65,6 +66,12 @@ function emitDouble(nullable: boolean): Nullable<DoubleTypeAnnotation> {
6566 } ) ;
6667}
6768
69+ function emitVoid ( nullable : boolean ) : Nullable < VoidTypeAnnotation > {
70+ return wrapNullable ( nullable , {
71+ type : 'VoidTypeAnnotation' ,
72+ } ) ;
73+ }
74+
6875function typeAliasResolution (
6976 typeAliasResolutionStatus : TypeAliasResolutionStatus ,
7077 objectTypeAnnotation : ObjectTypeAnnotation <
@@ -152,5 +159,6 @@ module.exports = {
152159 emitObject ,
153160 emitPromise ,
154161 emitRootTag ,
162+ emitVoid ,
155163 typeAliasResolution ,
156164} ;
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ const {
4545 emitObject,
4646 emitPromise,
4747 emitRootTag,
48+ emitVoid,
4849 typeAliasResolution,
4950} = require ( '../../parsers-primitives' ) ;
5051const {
@@ -380,9 +381,7 @@ function translateTypeAnnotation(
380381 return emitNumber ( nullable ) ;
381382 }
382383 case 'TSVoidKeyword': {
383- return wrapNullable ( nullable , {
384- type : 'VoidTypeAnnotation' ,
385- } ) ;
384+ return emitVoid ( nullable ) ;
386385 }
387386 case 'TSStringKeyword': {
388387 return wrapNullable ( nullable , {
You can’t perform that action at this time.
0 commit comments