Skip to content

Commit

Permalink
extracted nullguard function to parsers-util.js file (#34952)
Browse files Browse the repository at this point in the history
Summary:
This PR is a part of #34872
This PR extracts Extract the `nullGuard` function ([Flow](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L74-L76), [TypeScript](https://github.com/facebook/react-native/blob/main/packages/react-native-codegen/src/parsers/typescript/modules/index.js#L74-L76)) into a function in the `parsers-utils.js` file

## Changelog
[Internal] [Changed] - Extracted `nullGuard` function from flow and typescript to a file `parsers-utils.js`.

Pull Request resolved: #34952

Test Plan:
yarn jest react-native-codegen
<img width="1042" alt="Screenshot 2022-10-12 at 12 52 02 PM" src="https://user-images.githubusercontent.com/22423684/195277414-dc0122f4-603a-4e93-aef1-2ac0c33a960d.png">

Reviewed By: NickGerleman

Differential Revision: D40296951

Pulled By: cipolleschi

fbshipit-source-id: 4fb305fff2e28025496b65ec697d2a59cff77bde
  • Loading branch information
dakshbhardwaj authored and facebook-github-bot committed Oct 14, 2022
1 parent c388e6c commit 1eaa092
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {

import type {ParserErrorCapturer, TypeDeclarationMap} from '../../utils';
import type {NativeModuleTypeAnnotation} from '../../../CodegenSchema.js';
const {nullGuard} = require('../../parsers-utils');

const {throwIfMoreThanOneModuleRegistryCalls} = require('../../error-utils');
const {
Expand Down Expand Up @@ -76,10 +77,6 @@ const {

const language = 'Flow';

function nullGuard<T>(fn: () => T): ?T {
return fn();
}

function translateArrayTypeAnnotation(
hasteModuleName: string,
types: TypeDeclarationMap,
Expand Down
19 changes: 19 additions & 0 deletions packages/react-native-codegen/src/parsers/parsers-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 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';

function nullGuard<T>(fn: () => T): ?T {
return fn();
}

module.exports = {
nullGuard,
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {

import type {ParserErrorCapturer, TypeDeclarationMap} from '../../utils';
import type {NativeModuleTypeAnnotation} from '../../../CodegenSchema.js';
const {nullGuard} = require('../../parsers-utils');

const {throwIfMoreThanOneModuleRegistryCalls} = require('../../error-utils');
const {
Expand Down Expand Up @@ -76,10 +77,6 @@ const {

const language = 'TypeScript';

function nullGuard<T>(fn: () => T): ?T {
return fn();
}

function translateArrayTypeAnnotation(
hasteModuleName: string,
types: TypeDeclarationMap,
Expand Down

0 comments on commit 1eaa092

Please sign in to comment.