File tree Expand file tree Collapse file tree 4 files changed +69
-6
lines changed
packages/react-native-codegen/src/parsers Expand file tree Collapse file tree 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 {
3333 isModuleRegistryCall,
3434} = require ( '../utils.js' ) ;
3535const { unwrapNullable, wrapNullable} = require ( '../../parsers-commons' ) ;
36+ const { emitBoolean} = require ( '../../parsers-primitives' ) ;
3637const {
3738 IncorrectlyParameterizedFlowGenericParserError,
3839 MisnamedModuleFlowInterfaceParserError,
@@ -362,9 +363,7 @@ function translateTypeAnnotation(
362363 } ) ;
363364 }
364365 case 'BooleanTypeAnnotation' : {
365- return wrapNullable ( nullable , {
366- type : 'BooleanTypeAnnotation' ,
367- } ) ;
366+ return emitBoolean ( nullable ) ;
368367 }
369368 case 'NumberTypeAnnotation' : {
370369 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 {
3333 isModuleRegistryCall,
3434} = require ( '../utils.js' ) ;
3535const { unwrapNullable, wrapNullable} = require ( '../../parsers-commons' ) ;
36+ const { emitBoolean} = require ( '../../parsers-primitives' ) ;
3637const {
3738 IncorrectlyParameterizedTypeScriptGenericParserError,
3839 MisnamedModuleTypeScriptInterfaceParserError,
@@ -397,9 +398,7 @@ function translateTypeAnnotation(
397398 } ) ;
398399 }
399400 case 'TSBooleanKeyword ': {
400- return wrapNullable ( nullable , {
401- type : 'BooleanTypeAnnotation' ,
402- } ) ;
401+ return emitBoolean ( nullable ) ;
403402 }
404403 case 'TSNumberKeyword ': {
405404 return wrapNullable ( nullable , {
You can’t perform that action at this time.
0 commit comments