Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/

'use-strict';

const {emitBoolean} = require('../parsers-primitives.js');

describe('emitBoolean', () => {
describe('when nullable is true', () => {
it('returns nullable type annotation', () => {
const result = emitBoolean(true);
const expected = {
type: 'NullableTypeAnnotation',
typeAnnotation: {
type: 'BooleanTypeAnnotation',
},
};

expect(result).toEqual(expected);
});
});
describe('when nullable is false', () => {
it('returns non nullable type annotation', () => {
const result = emitBoolean(false);
const expected = {
type: 'BooleanTypeAnnotation',
};

expect(result).toEqual(expected);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const {
isModuleRegistryCall,
} = require('../utils.js');
const {unwrapNullable, wrapNullable} = require('../../parsers-commons');
const {emitBoolean} = require('../../parsers-primitives');
const {
IncorrectlyParameterizedFlowGenericParserError,
MisnamedModuleFlowInterfaceParserError,
Expand Down Expand Up @@ -362,9 +363,7 @@ function translateTypeAnnotation(
});
}
case 'BooleanTypeAnnotation': {
return wrapNullable(nullable, {
type: 'BooleanTypeAnnotation',
});
return emitBoolean(nullable);
}
case 'NumberTypeAnnotation': {
return wrapNullable(nullable, {
Expand Down
25 changes: 25 additions & 0 deletions packages/react-native-codegen/src/parsers/parsers-primitives.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow strict
*/

'use strict';

import type {BooleanTypeAnnotation, Nullable} from '../CodegenSchema';

const {wrapNullable} = require('./parsers-commons');

function emitBoolean(nullable: boolean): Nullable<BooleanTypeAnnotation> {
return wrapNullable(nullable, {
type: 'BooleanTypeAnnotation',
});
}

module.exports = {
emitBoolean,
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const {
isModuleRegistryCall,
} = require('../utils.js');
const {unwrapNullable, wrapNullable} = require('../../parsers-commons');
const {emitBoolean} = require('../../parsers-primitives');
const {
IncorrectlyParameterizedTypeScriptGenericParserError,
MisnamedModuleTypeScriptInterfaceParserError,
Expand Down Expand Up @@ -397,9 +398,7 @@ function translateTypeAnnotation(
});
}
case 'TSBooleanKeyword': {
return wrapNullable(nullable, {
type: 'BooleanTypeAnnotation',
});
return emitBoolean(nullable);
}
case 'TSNumberKeyword': {
return wrapNullable(nullable, {
Expand Down