From d4937b925bcd60df4c1bc8fda1cc83909aed9006 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ramos?= Date: Mon, 5 Oct 2020 12:55:09 -0700 Subject: [PATCH] Use correct var name for element when handling arrays of type aliases Summary: Fixes an issue where, if a spec uses an array of elements where the element is a type alias, the generated code would use the wrong variable name. An example of such a spec can be found in `NativeExceptionsManager.js`: ``` +reportSoftException: ( message: string, stack: Array, exceptionId: number, ) => void; ``` The fix ensures the local variable name is passed through, ensuring that either p or itemValue_N is used when appropriate. Changelog: [Internal] Reviewed By: RSNara Differential Revision: D24116429 fbshipit-source-id: f39b75adb604c751d70a284a11a7fa6649b1344d --- .../GenerateModuleObjCpp/header/serializeRegularStruct.js | 4 ++-- .../__snapshots__/GenerateModuleHObjCpp-test.js.snap | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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 6815dd05c54..76e9fa28646 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 @@ -195,8 +195,8 @@ function toObjCValue( ); return !isRequired - ? `(p == nil ? folly::none : folly::make_optional(${namespacedStructName}(p)))` - : `${namespacedStructName}(p)`; + ? `(${value} == nil ? folly::none : folly::make_optional(${namespacedStructName}(${value})))` + : `${namespacedStructName}(${value})`; default: (typeAnnotation.type: empty); throw new Error( diff --git a/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleHObjCpp-test.js.snap b/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleHObjCpp-test.js.snap index 2d7f078c525..3e71d06832a 100644 --- a/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleHObjCpp-test.js.snap +++ b/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleHObjCpp-test.js.snap @@ -309,7 +309,7 @@ inline folly::Optional> JS::NativeSample inline facebook::react::LazyVector JS::NativeSampleTurboModule::SpecGetArraysOptions::arrayOfObjects() const { id const p = _v[@\\"arrayOfObjects\\"]; - return RCTBridgingToVec(p, ^JS::NativeSampleTurboModule::SpecGetArraysOptionsArrayOfObjectsElement(id itemValue_0) { return JS::NativeSampleTurboModule::SpecGetArraysOptionsArrayOfObjectsElement(p); }); + return RCTBridgingToVec(p, ^JS::NativeSampleTurboModule::SpecGetArraysOptionsArrayOfObjectsElement(id itemValue_0) { return JS::NativeSampleTurboModule::SpecGetArraysOptionsArrayOfObjectsElement(itemValue_0); }); } ", @@ -890,7 +890,7 @@ inline NSString *JS::NativeExceptionsManager::ExceptionData::componentStack() co inline facebook::react::LazyVector JS::NativeExceptionsManager::ExceptionData::stack() const { id const p = _v[@\\"stack\\"]; - return RCTBridgingToVec(p, ^JS::NativeExceptionsManager::StackFrame(id itemValue_0) { return JS::NativeExceptionsManager::StackFrame(p); }); + return RCTBridgingToVec(p, ^JS::NativeExceptionsManager::StackFrame(id itemValue_0) { return JS::NativeExceptionsManager::StackFrame(itemValue_0); }); }