mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Remove folly import in GenerateModuleObjCpp
Summary: Changelog: [iOS][Changed] Replaced folly::Optional with std::optional from C++17 in Objc module generator. Reviewed By: philIip Differential Revision: D32367103 fbshipit-source-id: f0d254c4add7d6d2e0bdbceb09a852b4a01ea8c7
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d9f8ac2bc0
commit
45e2941367
+12
-12
@@ -79,15 +79,15 @@ function toObjCType(
|
||||
): string {
|
||||
const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation);
|
||||
const isRequired = !nullable && !isOptional;
|
||||
const wrapFollyOptional = (type: string) => {
|
||||
return isRequired ? type : `folly::Optional<${type}>`;
|
||||
const wrapOptional = (type: string) => {
|
||||
return isRequired ? type : `std::optional<${type}>`;
|
||||
};
|
||||
|
||||
switch (typeAnnotation.type) {
|
||||
case 'ReservedTypeAnnotation':
|
||||
switch (typeAnnotation.name) {
|
||||
case 'RootTag':
|
||||
return wrapFollyOptional('double');
|
||||
return wrapOptional('double');
|
||||
default:
|
||||
(typeAnnotation.name: empty);
|
||||
throw new Error(`Unknown prop type, found: ${typeAnnotation.name}"`);
|
||||
@@ -95,15 +95,15 @@ function toObjCType(
|
||||
case 'StringTypeAnnotation':
|
||||
return 'NSString *';
|
||||
case 'NumberTypeAnnotation':
|
||||
return wrapFollyOptional('double');
|
||||
return wrapOptional('double');
|
||||
case 'FloatTypeAnnotation':
|
||||
return wrapFollyOptional('double');
|
||||
return wrapOptional('double');
|
||||
case 'Int32TypeAnnotation':
|
||||
return wrapFollyOptional('double');
|
||||
return wrapOptional('double');
|
||||
case 'DoubleTypeAnnotation':
|
||||
return wrapFollyOptional('double');
|
||||
return wrapOptional('double');
|
||||
case 'BooleanTypeAnnotation':
|
||||
return wrapFollyOptional('bool');
|
||||
return wrapOptional('bool');
|
||||
case 'GenericObjectTypeAnnotation':
|
||||
return isRequired ? 'id<NSObject> ' : 'id<NSObject> _Nullable ';
|
||||
case 'ArrayTypeAnnotation':
|
||||
@@ -111,7 +111,7 @@ function toObjCType(
|
||||
return isRequired ? 'id<NSObject> ' : 'id<NSObject> _Nullable ';
|
||||
}
|
||||
|
||||
return wrapFollyOptional(
|
||||
return wrapOptional(
|
||||
`std::vector<${toObjCType(
|
||||
hasteModuleName,
|
||||
typeAnnotation.elementType,
|
||||
@@ -123,7 +123,7 @@ function toObjCType(
|
||||
hasteModuleName,
|
||||
structName,
|
||||
);
|
||||
return wrapFollyOptional(`${namespacedStructName}::Builder`);
|
||||
return wrapOptional(`${namespacedStructName}::Builder`);
|
||||
default:
|
||||
(typeAnnotation.type: empty);
|
||||
throw new Error(
|
||||
@@ -144,7 +144,7 @@ function toObjCValue(
|
||||
|
||||
function wrapPrimitive(type: string) {
|
||||
return !isRequired
|
||||
? `${value}.hasValue() ? @((${type})${value}.value()) : nil`
|
||||
? `${value}.has_value() ? @((${type})${value}.value()) : nil`
|
||||
: `@(${value})`;
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ function toObjCValue(
|
||||
);
|
||||
case 'TypeAliasTypeAnnotation':
|
||||
return !isRequired
|
||||
? `${value}.hasValue() ? ${value}.value().buildUnsafeRawValue() : nil`
|
||||
? `${value}.has_value() ? ${value}.value().buildUnsafeRawValue() : nil`
|
||||
: `${value}.buildUnsafeRawValue()`;
|
||||
default:
|
||||
(typeAnnotation.type: empty);
|
||||
|
||||
+11
-11
@@ -70,15 +70,15 @@ function toObjCType(
|
||||
): string {
|
||||
const [typeAnnotation, nullable] = unwrapNullable(nullableTypeAnnotation);
|
||||
const isRequired = !nullable && !isOptional;
|
||||
const wrapFollyOptional = (type: string) => {
|
||||
return isRequired ? type : `folly::Optional<${type}>`;
|
||||
const wrapOptional = (type: string) => {
|
||||
return isRequired ? type : `std::optional<${type}>`;
|
||||
};
|
||||
|
||||
switch (typeAnnotation.type) {
|
||||
case 'ReservedTypeAnnotation':
|
||||
switch (typeAnnotation.name) {
|
||||
case 'RootTag':
|
||||
return wrapFollyOptional('double');
|
||||
return wrapOptional('double');
|
||||
default:
|
||||
(typeAnnotation.name: empty);
|
||||
throw new Error(`Unknown prop type, found: ${typeAnnotation.name}"`);
|
||||
@@ -86,22 +86,22 @@ function toObjCType(
|
||||
case 'StringTypeAnnotation':
|
||||
return 'NSString *';
|
||||
case 'NumberTypeAnnotation':
|
||||
return wrapFollyOptional('double');
|
||||
return wrapOptional('double');
|
||||
case 'FloatTypeAnnotation':
|
||||
return wrapFollyOptional('double');
|
||||
return wrapOptional('double');
|
||||
case 'Int32TypeAnnotation':
|
||||
return wrapFollyOptional('double');
|
||||
return wrapOptional('double');
|
||||
case 'DoubleTypeAnnotation':
|
||||
return wrapFollyOptional('double');
|
||||
return wrapOptional('double');
|
||||
case 'BooleanTypeAnnotation':
|
||||
return wrapFollyOptional('bool');
|
||||
return wrapOptional('bool');
|
||||
case 'GenericObjectTypeAnnotation':
|
||||
return isRequired ? 'id<NSObject> ' : 'id<NSObject> _Nullable';
|
||||
case 'ArrayTypeAnnotation':
|
||||
if (typeAnnotation.elementType == null) {
|
||||
return isRequired ? 'id<NSObject> ' : 'id<NSObject> _Nullable';
|
||||
}
|
||||
return wrapFollyOptional(
|
||||
return wrapOptional(
|
||||
`facebook::react::LazyVector<${toObjCType(
|
||||
hasteModuleName,
|
||||
typeAnnotation.elementType,
|
||||
@@ -113,7 +113,7 @@ function toObjCType(
|
||||
hasteModuleName,
|
||||
structName,
|
||||
);
|
||||
return wrapFollyOptional(namespacedStructName);
|
||||
return wrapOptional(namespacedStructName);
|
||||
default:
|
||||
(typeAnnotation.type: empty);
|
||||
throw new Error(
|
||||
@@ -190,7 +190,7 @@ function toObjCValue(
|
||||
);
|
||||
|
||||
return !isRequired
|
||||
? `(${value} == nil ? folly::none : folly::make_optional(${namespacedStructName}(${value})))`
|
||||
? `(${value} == nil ? std::nullopt : std::make_optional(${namespacedStructName}(${value})))`
|
||||
: `${namespacedStructName}(${value})`;
|
||||
default:
|
||||
(typeAnnotation.type: empty);
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ const HeaderFileTemplate = ({
|
||||
#import <React/RCTCxxConvert.h>
|
||||
#import <React/RCTManagedPointer.h>
|
||||
#import <ReactCommon/RCTTurboModule.h>
|
||||
#import <folly/Optional.h>
|
||||
#import <optional>
|
||||
#import <vector>
|
||||
|
||||
` +
|
||||
|
||||
Reference in New Issue
Block a user