diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleCpp.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleCpp.js index b32b60c6f0e45a..1846ebc682677a 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleCpp.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleCpp.js @@ -22,7 +22,7 @@ import type { import type {AliasResolver} from './Utils'; const {createAliasResolver, getModules} = require('./Utils'); -const {unwrapNullable} = require('../../parsers/flow/modules/utils'); +const {unwrapNullable} = require('../../parsers/parsers-commons'); type FilesOutput = Map; diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js index 7c80bad095e1f8..dad386c4c9e7a9 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleH.js @@ -21,7 +21,7 @@ import type { import type {AliasResolver} from './Utils'; const {createAliasResolver, getModules} = require('./Utils'); const {indent} = require('../Utils'); -const {unwrapNullable} = require('../../parsers/flow/modules/utils'); +const {unwrapNullable} = require('../../parsers/parsers-commons'); type FilesOutput = Map; diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js index 32443237f3a8e2..0715932adbbeb3 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleJavaSpec.js @@ -22,7 +22,7 @@ import type { import type {AliasResolver} from './Utils'; const {createAliasResolver, getModules} = require('./Utils'); -const {unwrapNullable} = require('../../parsers/flow/modules/utils'); +const {unwrapNullable} = require('../../parsers/parsers-commons'); type FilesOutput = Map; diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleJniCpp.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleJniCpp.js index aa56ed608c872b..2703c2517227ad 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleJniCpp.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleJniCpp.js @@ -22,7 +22,7 @@ import type { import type {AliasResolver} from './Utils'; const {createAliasResolver, getModules} = require('./Utils'); -const {unwrapNullable} = require('../../parsers/flow/modules/utils'); +const {unwrapNullable} = require('../../parsers/parsers-commons'); type FilesOutput = Map; diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/StructCollector.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/StructCollector.js index a30fa5400ecf70..d3926812c3bd0d 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/StructCollector.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/StructCollector.js @@ -32,7 +32,7 @@ const {capitalize} = require('../../Utils'); const { unwrapNullable, wrapNullable, -} = require('../../../parsers/flow/modules/utils'); +} = require('../../../parsers/parsers-commons'); type StructContext = 'CONSTANTS' | 'REGULAR'; diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js index 019724049a15bc..d030fdcf442a9a 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js @@ -17,7 +17,7 @@ import type {Nullable} from '../../../../CodegenSchema'; import type {StructTypeAnnotation, ConstantsStruct} from '../StructCollector'; import type {StructSerilizationOutput} from './serializeStruct'; -const {unwrapNullable} = require('../../../../parsers/flow/modules/utils'); +const {unwrapNullable} = require('../../../../parsers/parsers-commons'); const StructTemplate = ({ hasteModuleName, diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js index e17c30005d411b..9cc4aee79ab486 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js @@ -17,7 +17,7 @@ import type {Nullable} from '../../../../CodegenSchema'; import type {StructTypeAnnotation, RegularStruct} from '../StructCollector'; import type {StructSerilizationOutput} from './serializeStruct'; -const {unwrapNullable} = require('../../../../parsers/flow/modules/utils'); +const {unwrapNullable} = require('../../../../parsers/parsers-commons'); const StructTemplate = ({ hasteModuleName, diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/serializeMethod.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/serializeMethod.js index ead5482a824d4b..91bcba56ec2ef9 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/serializeMethod.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleObjCpp/serializeMethod.js @@ -27,7 +27,7 @@ const {capitalize} = require('../../Utils'); const { wrapNullable, unwrapNullable, -} = require('../../../parsers/flow/modules/utils'); +} = require('../../../parsers/parsers-commons'); const ProtocolMethodTemplate = ({ returnObjCType, diff --git a/packages/react-native-codegen/src/parsers/flow/modules/__tests__/module-parser-e2e-test.js b/packages/react-native-codegen/src/parsers/flow/modules/__tests__/module-parser-e2e-test.js index 25240c0a26beee..c40bbf8ecac3f4 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/__tests__/module-parser-e2e-test.js +++ b/packages/react-native-codegen/src/parsers/flow/modules/__tests__/module-parser-e2e-test.js @@ -16,7 +16,7 @@ import type { } from '../../../../CodegenSchema'; const {parseString} = require('../../index.js'); -const {unwrapNullable} = require('../utils'); +const {unwrapNullable} = require('../../../parsers-commons'); const { UnsupportedFlowGenericParserError, UnsupportedFlowTypeAnnotationParserError, diff --git a/packages/react-native-codegen/src/parsers/flow/modules/index.js b/packages/react-native-codegen/src/parsers/flow/modules/index.js index 4ced736958f7e6..7150ab2296cec5 100644 --- a/packages/react-native-codegen/src/parsers/flow/modules/index.js +++ b/packages/react-native-codegen/src/parsers/flow/modules/index.js @@ -32,7 +32,7 @@ const { visit, isModuleRegistryCall, } = require('../utils.js'); -const {unwrapNullable, wrapNullable} = require('./utils'); +const {unwrapNullable, wrapNullable} = require('../../parsers-commons'); const { IncorrectlyParameterizedFlowGenericParserError, MisnamedModuleFlowInterfaceParserError, diff --git a/packages/react-native-codegen/src/parsers/flow/modules/utils.js b/packages/react-native-codegen/src/parsers/flow/modules/utils.js deleted file mode 100644 index b013f76c8ce59e..00000000000000 --- a/packages/react-native-codegen/src/parsers/flow/modules/utils.js +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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 - * @format - */ - -'use strict'; - -import type { - NativeModuleTypeAnnotation, - Nullable, -} from '../../../CodegenSchema.js'; - -function unwrapNullable<+T: NativeModuleTypeAnnotation>( - x: Nullable, -): [T, boolean] { - if (x.type === 'NullableTypeAnnotation') { - return [x.typeAnnotation, true]; - } - - return [x, false]; -} - -function wrapNullable<+T: NativeModuleTypeAnnotation>( - nullable: boolean, - typeAnnotation: T, -): Nullable { - if (!nullable) { - return typeAnnotation; - } - - return { - type: 'NullableTypeAnnotation', - typeAnnotation, - }; -} - -module.exports = { - unwrapNullable, - wrapNullable, -}; diff --git a/packages/react-native-codegen/src/parsers/parsers-commons.js b/packages/react-native-codegen/src/parsers/parsers-commons.js index 3e856f4dd7332f..d77fbfacd724c1 100644 --- a/packages/react-native-codegen/src/parsers/parsers-commons.js +++ b/packages/react-native-codegen/src/parsers/parsers-commons.js @@ -10,7 +10,12 @@ 'use strict'; -import type {SchemaType, NativeModuleSchema} from '../CodegenSchema.js'; +import type { + SchemaType, + NativeModuleSchema, + NativeModuleTypeAnnotation, + Nullable, +} from '../CodegenSchema.js'; function wrapModuleSchema( nativeModuleSchema: NativeModuleSchema, @@ -23,6 +28,32 @@ function wrapModuleSchema( }; } +function unwrapNullable<+T: NativeModuleTypeAnnotation>( + x: Nullable, +): [T, boolean] { + if (x.type === 'NullableTypeAnnotation') { + return [x.typeAnnotation, true]; + } + + return [x, false]; +} + +function wrapNullable<+T: NativeModuleTypeAnnotation>( + nullable: boolean, + typeAnnotation: T, +): Nullable { + if (!nullable) { + return typeAnnotation; + } + + return { + type: 'NullableTypeAnnotation', + typeAnnotation, + }; +} + module.exports = { wrapModuleSchema, + unwrapNullable, + wrapNullable, }; diff --git a/packages/react-native-codegen/src/parsers/typescript/modules/__tests__/typescript-module-parser-e2e-test.js b/packages/react-native-codegen/src/parsers/typescript/modules/__tests__/typescript-module-parser-e2e-test.js index 99b7702f5fd640..17aa2b1dbc64bc 100644 --- a/packages/react-native-codegen/src/parsers/typescript/modules/__tests__/typescript-module-parser-e2e-test.js +++ b/packages/react-native-codegen/src/parsers/typescript/modules/__tests__/typescript-module-parser-e2e-test.js @@ -16,7 +16,7 @@ import type { } from '../../../../CodegenSchema'; const {parseString} = require('../../index.js'); -const {unwrapNullable} = require('../utils'); +const {unwrapNullable} = require('../../../parsers-commons'); const { UnsupportedTypeScriptGenericParserError, UnsupportedTypeScriptTypeAnnotationParserError, diff --git a/packages/react-native-codegen/src/parsers/typescript/modules/index.js b/packages/react-native-codegen/src/parsers/typescript/modules/index.js index 893d6e69520fd1..76b8aaf3ed931c 100644 --- a/packages/react-native-codegen/src/parsers/typescript/modules/index.js +++ b/packages/react-native-codegen/src/parsers/typescript/modules/index.js @@ -32,7 +32,7 @@ const { visit, isModuleRegistryCall, } = require('../utils.js'); -const {unwrapNullable, wrapNullable} = require('./utils'); +const {unwrapNullable, wrapNullable} = require('../../parsers-commons'); const { IncorrectlyParameterizedTypeScriptGenericParserError, MisnamedModuleTypeScriptInterfaceParserError, diff --git a/packages/react-native-codegen/src/parsers/typescript/modules/utils.js b/packages/react-native-codegen/src/parsers/typescript/modules/utils.js deleted file mode 100644 index b013f76c8ce59e..00000000000000 --- a/packages/react-native-codegen/src/parsers/typescript/modules/utils.js +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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 - * @format - */ - -'use strict'; - -import type { - NativeModuleTypeAnnotation, - Nullable, -} from '../../../CodegenSchema.js'; - -function unwrapNullable<+T: NativeModuleTypeAnnotation>( - x: Nullable, -): [T, boolean] { - if (x.type === 'NullableTypeAnnotation') { - return [x.typeAnnotation, true]; - } - - return [x, false]; -} - -function wrapNullable<+T: NativeModuleTypeAnnotation>( - nullable: boolean, - typeAnnotation: T, -): Nullable { - if (!nullable) { - return typeAnnotation; - } - - return { - type: 'NullableTypeAnnotation', - typeAnnotation, - }; -} - -module.exports = { - unwrapNullable, - wrapNullable, -};