From fc26dbfce0ed16edf1efcfebc01dd4ca584eb902 Mon Sep 17 00:00:00 2001 From: Chiara Mooney <34109996+chiaramooney@users.noreply.github.com> Date: Mon, 1 Aug 2022 20:54:59 -0700 Subject: [PATCH] Fix Macro Errors for Windows (#34299) Summary: Fix macro errors for Windows. Current syntax breaks the build of the React Common project on Windows because the ({...}) syntax is not supported; must be replaced with lambda expressions. Resolves https://github.com/facebook/react-native/issues/34090 ## Changelog [General] [Fixed] - Fix macro errors for Windows. lyahdav JoshuaGross Pull Request resolved: https://github.com/facebook/react-native/pull/34299 Test Plan: Build on react-native-windows repo. Tested in RNW app. Reviewed By: javache Differential Revision: D38272966 Pulled By: NickGerleman fbshipit-source-id: e76eac11cde173ef49465d01d793c593017f2ab7 --- .../components/text/BaseTextProps.cpp | 8 +++---- .../renderer/components/view/ViewProps.cpp | 23 ++++++++++--------- .../core/ConcreteComponentDescriptor.h | 2 +- ReactCommon/react/renderer/core/PropsMacros.h | 8 +++---- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/ReactCommon/react/renderer/components/text/BaseTextProps.cpp b/ReactCommon/react/renderer/components/text/BaseTextProps.cpp index e93c000d1b2cbf..b660b6d7cbbc3a 100644 --- a/ReactCommon/react/renderer/components/text/BaseTextProps.cpp +++ b/ReactCommon/react/renderer/components/text/BaseTextProps.cpp @@ -13,12 +13,12 @@ #include #define GET_FIELD_VALUE(field, fieldName, defaultValue, rawValue) \ - (rawValue.hasValue() ? ({ \ + (rawValue.hasValue() ? ([&rawValue, &context] { \ decltype(defaultValue) res; \ fromRawValue(context, rawValue, res); \ - res; \ - }) \ - : defaultValue) + return res; \ + }()) \ + : defaultValue); #define REBUILD_FIELD_SWITCH_CASE( \ defaults, rawValue, property, field, fieldName) \ diff --git a/ReactCommon/react/renderer/components/view/ViewProps.cpp b/ReactCommon/react/renderer/components/view/ViewProps.cpp index f04753da8935ee..10067604153056 100644 --- a/ReactCommon/react/renderer/components/view/ViewProps.cpp +++ b/ReactCommon/react/renderer/components/view/ViewProps.cpp @@ -258,17 +258,18 @@ ViewProps::ViewProps( #endif {}; -#define VIEW_EVENT_CASE(eventType, eventString) \ - case CONSTEXPR_RAW_PROPS_KEY_HASH(eventString): { \ - ViewEvents defaultViewEvents{}; \ - events[eventType] = ({ \ - bool res = defaultViewEvents[eventType]; \ - if (value.hasValue()) { \ - fromRawValue(context, value, res); \ - } \ - res; \ - }); \ - return; \ +#define VIEW_EVENT_CASE(eventType, eventString) \ + case CONSTEXPR_RAW_PROPS_KEY_HASH(eventString): { \ + ViewEvents defaultViewEvents{}; \ + events[eventType] = [ defaultViewEvents, &value, &context ]() constexpr { \ + bool res = defaultViewEvents[eventType]; \ + if (value.hasValue()) { \ + fromRawValue(context, value, res); \ + } \ + return res; \ + } \ + (); \ + return; \ } void ViewProps::setProp( diff --git a/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h b/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h index 77c60b0a1356dd..b2657e037f0c2f 100644 --- a/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h +++ b/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h @@ -119,7 +119,7 @@ class ConcreteComponentDescriptor : public ComponentDescriptor { rawProps.iterateOverValues([&](RawPropsPropNameHash hash, const char *propName, RawValue const &fn) { - shadowNodeProps.get()->setProp(context, hash, propName, fn); + shadowNodeProps.get()->Props::setProp(context, hash, propName, fn); }); } diff --git a/ReactCommon/react/renderer/core/PropsMacros.h b/ReactCommon/react/renderer/core/PropsMacros.h index 1e7a6c51a14ce6..9064031bac8606 100644 --- a/ReactCommon/react/renderer/core/PropsMacros.h +++ b/ReactCommon/react/renderer/core/PropsMacros.h @@ -19,14 +19,12 @@ // Get hash at compile-time. sizeof(str) - 1 == strlen #define CONSTEXPR_RAW_PROPS_KEY_HASH(s) \ - ({ \ + ([]() constexpr { \ CLANG_PRAGMA("clang diagnostic push") \ CLANG_PRAGMA("clang diagnostic ignored \"-Wshadow\"") \ - constexpr RawPropsPropNameHash propNameHash = \ - folly::hash::fnv32_buf(s, sizeof(s) - 1); \ - propNameHash; \ + return folly::hash::fnv32_buf(s, sizeof(s) - 1); \ CLANG_PRAGMA("clang diagnostic pop") \ - }) + }()) #define RAW_PROPS_KEY_HASH(s) folly::hash::fnv32_buf(s, std::strlen(s))