mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Support optional types for C++ TurboModules
Summary: Update C++ TurboModule codegen to wrap nullable types in `std::optional` whereas before the conversion would cause a crash. Changelog: Internal Reviewed By: mdvacca, nlutsenko Differential Revision: D35299708 fbshipit-source-id: 7daa50fe8b16879c5b3a55a633aa3f724dc5be30
This commit is contained in:
committed by
Facebook GitHub Bot
parent
370f1ca0cd
commit
6e0fa5f15e
@@ -105,19 +105,26 @@ function serializeArg(
|
||||
index: number,
|
||||
resolveAlias: AliasResolver,
|
||||
): string {
|
||||
function wrap(suffix) {
|
||||
return `args[${index}]${suffix}`;
|
||||
}
|
||||
const {typeAnnotation: nullableTypeAnnotation} = arg;
|
||||
const [typeAnnotation] = unwrapNullable<NativeModuleParamTypeAnnotation>(
|
||||
nullableTypeAnnotation,
|
||||
);
|
||||
const [typeAnnotation, nullable] =
|
||||
unwrapNullable<NativeModuleParamTypeAnnotation>(nullableTypeAnnotation);
|
||||
|
||||
let realTypeAnnotation = typeAnnotation;
|
||||
if (realTypeAnnotation.type === 'TypeAliasTypeAnnotation') {
|
||||
realTypeAnnotation = resolveAlias(realTypeAnnotation.name);
|
||||
}
|
||||
|
||||
function wrap(suffix) {
|
||||
const val = `args[${index}]`;
|
||||
const expression = `${val}${suffix}`;
|
||||
|
||||
if (nullable) {
|
||||
return `${val}.isNull() || ${val}.isUndefined() ? std::nullopt : std::make_optional(${expression})`;
|
||||
}
|
||||
|
||||
return expression;
|
||||
}
|
||||
|
||||
switch (realTypeAnnotation.type) {
|
||||
case 'ReservedTypeAnnotation':
|
||||
switch (realTypeAnnotation.name) {
|
||||
|
||||
Reference in New Issue
Block a user