File tree 4 files changed +69
-6
lines changed
packages/react-native-codegen/src/parsers
4 files changed +69
-6
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ * @oncall react_native
10
+ */
11
+
12
+ 'use-strict' ;
13
+
14
+ const { emitBoolean} = require ( '../parsers-primitives.js' ) ;
15
+
16
+ describe ( 'emitBoolean' , ( ) => {
17
+ describe ( 'when nullable is true' , ( ) => {
18
+ it ( 'returns nullable type annotation' , ( ) => {
19
+ const result = emitBoolean ( true ) ;
20
+ const expected = {
21
+ type : 'NullableTypeAnnotation' ,
22
+ typeAnnotation : {
23
+ type : 'BooleanTypeAnnotation' ,
24
+ } ,
25
+ } ;
26
+
27
+ expect ( result ) . toEqual ( expected ) ;
28
+ } ) ;
29
+ } ) ;
30
+ describe ( 'when nullable is false' , ( ) => {
31
+ it ( 'returns non nullable type annotation' , ( ) => {
32
+ const result = emitBoolean ( false ) ;
33
+ const expected = {
34
+ type : 'BooleanTypeAnnotation' ,
35
+ } ;
36
+
37
+ expect ( result ) . toEqual ( expected ) ;
38
+ } ) ;
39
+ } ) ;
40
+ } ) ;
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ const {
33
33
isModuleRegistryCall,
34
34
} = require ( '../utils.js' ) ;
35
35
const { unwrapNullable, wrapNullable} = require ( '../../parsers-commons' ) ;
36
+ const { emitBoolean} = require ( '../../parsers-primitives' ) ;
36
37
const {
37
38
IncorrectlyParameterizedFlowGenericParserError,
38
39
MisnamedModuleFlowInterfaceParserError,
@@ -362,9 +363,7 @@ function translateTypeAnnotation(
362
363
} ) ;
363
364
}
364
365
case 'BooleanTypeAnnotation' : {
365
- return wrapNullable ( nullable , {
366
- type : 'BooleanTypeAnnotation' ,
367
- } ) ;
366
+ return emitBoolean ( nullable ) ;
368
367
}
369
368
case 'NumberTypeAnnotation' : {
370
369
return wrapNullable ( nullable , {
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow strict
9
+ */
10
+
11
+ 'use strict' ;
12
+
13
+ import type { BooleanTypeAnnotation , Nullable } from '../CodegenSchema' ;
14
+
15
+ const { wrapNullable} = require ( './parsers-commons' ) ;
16
+
17
+ function emitBoolean ( nullable : boolean ) : Nullable < BooleanTypeAnnotation > {
18
+ return wrapNullable ( nullable , {
19
+ type : 'BooleanTypeAnnotation' ,
20
+ } ) ;
21
+ }
22
+
23
+ module . exports = {
24
+ emitBoolean,
25
+ } ;
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ const {
33
33
isModuleRegistryCall,
34
34
} = require ( '../utils.js' ) ;
35
35
const { unwrapNullable, wrapNullable} = require ( '../../parsers-commons' ) ;
36
+ const { emitBoolean} = require ( '../../parsers-primitives' ) ;
36
37
const {
37
38
IncorrectlyParameterizedTypeScriptGenericParserError,
38
39
MisnamedModuleTypeScriptInterfaceParserError,
@@ -397,9 +398,7 @@ function translateTypeAnnotation(
397
398
} ) ;
398
399
}
399
400
case 'TSBooleanKeyword ': {
400
- return wrapNullable ( nullable , {
401
- type : 'BooleanTypeAnnotation' ,
402
- } ) ;
401
+ return emitBoolean ( nullable ) ;
403
402
}
404
403
case 'TSNumberKeyword ': {
405
404
return wrapNullable ( nullable , {
You can’t perform that action at this time.
0 commit comments