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
Expand Up @@ -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<string, string>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const {capitalize} = require('../../Utils');
const {
unwrapNullable,
wrapNullable,
} = require('../../../parsers/flow/modules/utils');
} = require('../../../parsers/parsers-commons');

type StructContext = 'CONSTANTS' | 'REGULAR';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const {capitalize} = require('../../Utils');
const {
wrapNullable,
unwrapNullable,
} = require('../../../parsers/flow/modules/utils');
} = require('../../../parsers/parsers-commons');

const ProtocolMethodTemplate = ({
returnObjCType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const {
visit,
isModuleRegistryCall,
} = require('../utils.js');
const {unwrapNullable, wrapNullable} = require('./utils');
const {unwrapNullable, wrapNullable} = require('../../parsers-commons');
const {
IncorrectlyParameterizedFlowGenericParserError,
MisnamedModuleFlowInterfaceParserError,
Expand Down
45 changes: 0 additions & 45 deletions packages/react-native-codegen/src/parsers/flow/modules/utils.js

This file was deleted.

33 changes: 32 additions & 1 deletion packages/react-native-codegen/src/parsers/parsers-commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -23,6 +28,32 @@ function wrapModuleSchema(
};
}

function unwrapNullable<+T: NativeModuleTypeAnnotation>(
x: Nullable<T>,
): [T, boolean] {
if (x.type === 'NullableTypeAnnotation') {
return [x.typeAnnotation, true];
}

return [x, false];
}

function wrapNullable<+T: NativeModuleTypeAnnotation>(
nullable: boolean,
typeAnnotation: T,
): Nullable<T> {
if (!nullable) {
return typeAnnotation;
}

return {
type: 'NullableTypeAnnotation',
typeAnnotation,
};
}

module.exports = {
wrapModuleSchema,
unwrapNullable,
wrapNullable,
};
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const {
visit,
isModuleRegistryCall,
} = require('../utils.js');
const {unwrapNullable, wrapNullable} = require('./utils');
const {unwrapNullable, wrapNullable} = require('../../parsers-commons');
const {
IncorrectlyParameterizedTypeScriptGenericParserError,
MisnamedModuleTypeScriptInterfaceParserError,
Expand Down

This file was deleted.