-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract contents of the case 'BooleanTypeAnnotation' into a single em…
…itBoolean function (#34907) Summary: Part of #34872 This PR extracts the content of the case 'BooleanTypeAnnotation' ([Flow](https://github.com/facebook/react-native/blob/b444f0e44e0d8670139acea5f14c2de32c5e2ddc/packages/react-native-codegen/src/parsers/flow/modules/index.js#L365-L367), [TypeScript](https://github.com/facebook/react-native/blob/00b795642a6562fb52d6df12e367b84674994623/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L400-L402)) into a single emitBoolean function in the parsers-primitives.js file. Use the new function in the parsers. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [Internal] [Changed] - Extract contents of the case 'BooleanTypeAnnotation' into a single emitBoolean function Pull Request resolved: #34907 Test Plan: Run ```yarn jest react-native-codegen``` <img width="803" alt="image" src="https://user-images.githubusercontent.com/34857453/194751101-3b1a619e-332a-43a9-bfa3-35f5869d7c5f.png"> Reviewed By: cipolleschi Differential Revision: D40212518 Pulled By: cipolleschi fbshipit-source-id: 9c1462c1e51a1836f963866dc4101f081898df00
- Loading branch information
1 parent
7227bde
commit 7a2e346
Showing
4 changed files
with
69 additions
and
6 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
packages/react-native-codegen/src/parsers/__tests__/parsers-primitives-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/react-native-codegen/src/parsers/parsers-primitives.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters