mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Changelog: [General][BREAKING] Don't support 'float' enums in Turbo Modules - The current implementation of 'float enums' in C++ does not work as invalid results are returned. - At potential fix could still cause rounding errors when crossing language bounaries, e.g. `4.6` can become `4.5599999942..` - C++ enum classes don't support float: https://eel.is/c++draft/dcl.enum#2.sentence-4 > The type-specifier-seq of an enum-base shall name an integral type; any cv-qualification is ignored. Hence removing the feature of `float enums` for now Reviewed By: NickGerleman Differential Revision: D52120405 fbshipit-source-id: 3685ad0629e16ff9db424ba67e07d09df6027553
86 lines
2.2 KiB
JavaScript
86 lines
2.2 KiB
JavaScript
/**
|
|
* 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 {
|
|
NativeModuleAliasMap,
|
|
NativeModuleObjectTypeAnnotation,
|
|
NativeModuleSchema,
|
|
NativeModuleTypeAnnotation,
|
|
Nullable,
|
|
SchemaType,
|
|
} from '../../CodegenSchema';
|
|
|
|
const {unwrapNullable} = require('../../parsers/parsers-commons');
|
|
const invariant = require('invariant');
|
|
|
|
export type AliasResolver = (
|
|
aliasName: string,
|
|
) => NativeModuleObjectTypeAnnotation;
|
|
|
|
function createAliasResolver(aliasMap: NativeModuleAliasMap): AliasResolver {
|
|
return (aliasName: string) => {
|
|
const alias = aliasMap[aliasName];
|
|
invariant(alias != null, `Unable to resolve type alias '${aliasName}'.`);
|
|
return alias;
|
|
};
|
|
}
|
|
|
|
function getModules(
|
|
schema: SchemaType,
|
|
): $ReadOnly<{[hasteModuleName: string]: NativeModuleSchema}> {
|
|
return Object.keys(schema.modules).reduce<{[string]: NativeModuleSchema}>(
|
|
(modules, hasteModuleName: string) => {
|
|
const module = schema.modules[hasteModuleName];
|
|
if (module == null || module.type === 'Component') {
|
|
return modules;
|
|
}
|
|
modules[hasteModuleName] = module;
|
|
return modules;
|
|
},
|
|
{},
|
|
);
|
|
}
|
|
|
|
function isDirectRecursiveMember(
|
|
parentObjectAliasName: ?string,
|
|
nullableTypeAnnotation: Nullable<NativeModuleTypeAnnotation>,
|
|
): boolean {
|
|
const [typeAnnotation] = unwrapNullable<NativeModuleTypeAnnotation>(
|
|
nullableTypeAnnotation,
|
|
);
|
|
return (
|
|
parentObjectAliasName !== undefined &&
|
|
typeAnnotation.name === parentObjectAliasName
|
|
);
|
|
}
|
|
|
|
function isArrayRecursiveMember(
|
|
parentObjectAliasName: ?string,
|
|
nullableTypeAnnotation: Nullable<NativeModuleTypeAnnotation>,
|
|
): boolean {
|
|
const [typeAnnotation] = unwrapNullable<NativeModuleTypeAnnotation>(
|
|
nullableTypeAnnotation,
|
|
);
|
|
return (
|
|
parentObjectAliasName !== undefined &&
|
|
typeAnnotation.type === 'ArrayTypeAnnotation' &&
|
|
typeAnnotation.elementType?.name === parentObjectAliasName
|
|
);
|
|
}
|
|
|
|
module.exports = {
|
|
createAliasResolver,
|
|
getModules,
|
|
isDirectRecursiveMember,
|
|
isArrayRecursiveMember,
|
|
};
|