Skip to content

Commit 1eaa092

Browse files
dakshbhardwajfacebook-github-bot
authored andcommitted
extracted nullguard function to parsers-util.js file (#34952)
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
1 parent c388e6c commit 1eaa092

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

packages/react-native-codegen/src/parsers/flow/modules/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import type {
2424

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

2829
const {throwIfMoreThanOneModuleRegistryCalls} = require('../../error-utils');
2930
const {
@@ -76,10 +77,6 @@ const {
7677

7778
const language = 'Flow';
7879

79-
function nullGuard<T>(fn: () => T): ?T {
80-
return fn();
81-
}
82-
8380
function translateArrayTypeAnnotation(
8481
hasteModuleName: string,
8582
types: TypeDeclarationMap,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
function nullGuard<T>(fn: () => T): ?T {
14+
return fn();
15+
}
16+
17+
module.exports = {
18+
nullGuard,
19+
};

packages/react-native-codegen/src/parsers/typescript/modules/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import type {
2424

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

2829
const {throwIfMoreThanOneModuleRegistryCalls} = require('../../error-utils');
2930
const {
@@ -76,10 +77,6 @@ const {
7677

7778
const language = 'TypeScript';
7879

79-
function nullGuard<T>(fn: () => T): ?T {
80-
return fn();
81-
}
82-
8380
function translateArrayTypeAnnotation(
8481
hasteModuleName: string,
8582
types: TypeDeclarationMap,

0 commit comments

Comments
 (0)