File tree Expand file tree Collapse file tree 4 files changed +45
-10
lines changed
packages/react-native-codegen/src/parsers Expand file tree Collapse file tree 4 files changed +45
-10
lines changed Original file line number Diff line number Diff line change @@ -16,9 +16,10 @@ const {
1616 emitDouble,
1717 emitNumber,
1818 emitInt32,
19+ emitObject,
20+ emitPromise,
1921 emitRootTag,
2022 typeAliasResolution,
21- emitPromise,
2223} = require ( '../parsers-primitives.js' ) ;
2324
2425describe ( 'emitBoolean' , ( ) => {
@@ -315,3 +316,29 @@ describe('emitPromise', () => {
315316 } ) ;
316317 } ) ;
317318} ) ;
319+
320+ describe ( 'emitObject' , ( ) => {
321+ describe ( 'when nullable is true' , ( ) => {
322+ it ( 'returns nullable type annotation' , ( ) => {
323+ const result = emitObject ( true ) ;
324+ const expected = {
325+ type : 'NullableTypeAnnotation' ,
326+ typeAnnotation : {
327+ type : 'GenericObjectTypeAnnotation' ,
328+ } ,
329+ } ;
330+
331+ expect ( result ) . toEqual ( expected ) ;
332+ } ) ;
333+ } ) ;
334+ describe ( 'when nullable is false' , ( ) => {
335+ it ( 'returns non nullable type annotation' , ( ) => {
336+ const result = emitObject ( false ) ;
337+ const expected = {
338+ type : 'GenericObjectTypeAnnotation' ,
339+ } ;
340+
341+ expect ( result ) . toEqual ( expected ) ;
342+ } ) ;
343+ } ) ;
344+ } ) ;
Original file line number Diff line number Diff line change @@ -42,9 +42,10 @@ const {
4242 emitDouble,
4343 emitNumber,
4444 emitInt32,
45+ emitObject,
46+ emitPromise,
4547 emitRootTag,
4648 typeAliasResolution,
47- emitPromise,
4849} = require ( '../../parsers-primitives' ) ;
4950const {
5051 MisnamedModuleInterfaceParserError,
@@ -218,9 +219,7 @@ function translateTypeAnnotation(
218219 }
219220 case 'UnsafeObject':
220221 case 'Object': {
221- return wrapNullable ( nullable , {
222- type : 'GenericObjectTypeAnnotation' ,
223- } ) ;
222+ return emitObject ( nullable ) ;
224223 }
225224 default: {
226225 const maybeEumDeclaration = types [ typeAnnotation . id . name ] ;
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import type {
1919 BooleanTypeAnnotation ,
2020 DoubleTypeAnnotation ,
2121 Int32TypeAnnotation ,
22+ NativeModuleGenericObjectTypeAnnotation ,
2223 ReservedTypeAnnotation ,
2324 ObjectTypeAnnotation ,
2425 NativeModulePromiseTypeAnnotation ,
@@ -135,12 +136,21 @@ function emitPromise(
135136 } ) ;
136137}
137138
139+ function emitObject (
140+ nullable : boolean ,
141+ ) : Nullable < NativeModuleGenericObjectTypeAnnotation > {
142+ return wrapNullable ( nullable , {
143+ type : 'GenericObjectTypeAnnotation' ,
144+ } ) ;
145+ }
146+
138147module.exports = {
139148 emitBoolean ,
140149 emitDouble ,
141150 emitInt32 ,
142151 emitNumber ,
152+ emitObject ,
153+ emitPromise ,
143154 emitRootTag ,
144155 typeAliasResolution ,
145- emitPromise,
146156} ;
Original file line number Diff line number Diff line change @@ -42,9 +42,10 @@ const {
4242 emitDouble,
4343 emitNumber,
4444 emitInt32,
45+ emitObject,
46+ emitPromise,
4547 emitRootTag,
4648 typeAliasResolution,
47- emitPromise,
4849} = require ( '../../parsers-primitives' ) ;
4950const {
5051 MisnamedModuleInterfaceParserError,
@@ -251,9 +252,7 @@ function translateTypeAnnotation(
251252 }
252253 case 'UnsafeObject':
253254 case 'Object': {
254- return wrapNullable ( nullable , {
255- type : 'GenericObjectTypeAnnotation' ,
256- } ) ;
255+ return emitObject ( nullable ) ;
257256 }
258257 default: {
259258 const maybeEumDeclaration = types [ typeAnnotation . typeName . name ] ;
You can’t perform that action at this time.
0 commit comments